+ 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])

12th Dec 2018, 12:30 AM
Sotomi Oluwadmilola
3 Respuestas
+ 2
Yes..thanks
12th Dec 2018, 12:54 AM
Sotomi Oluwadmilola
+ 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])
12th Dec 2018, 12:52 AM
HonFu
HonFu - avatar
0
] nums а дальше 🐷🐷
14th Dec 2018, 7:22 AM
андрей шипунов
андрей шипунов - avatar