+ 2
Shouldn't the 2nd and third line of this code display a list of integers just like the lesson in "list comprehension"
Shouldn't the 2nd and third line display a list of integers just like the lesson in "list comprehension" in python instead of the true and false its displaying nums = [55, 44, 33, 22, 11] Print([i > 5 for i in nums]) Print([i % 2 == 0 for i in nums])
3 Respostas
+ 2
Yes..thanks
+ 1
To understand list comprehensions better, you can try to read them backwards:
for i in nums:
evaluate i>5
(or i%2==0) and
put the result in that list.
So the result of the boolean expression will be put to the list.
Are you maybe looking for something like this?
print([i for i in nums if i>5])
0
] nums а дальше 🐷🐷