The third list comprehension lst3
doesn't work when the for
statement is written first. I am trying to understand why lst3
doesn't work similarly as lst1
...
lst1 = [i for i in range(20) if (i % 2 == 0) if (i % 3 == 0 ) if (i% 12 ==0) ]
print(lst2)
lst2 = [i if (i % 2 == 0) else "odd" for i in range(20)]
print(lst2)
lst3 = [i for i in range(20) if (i % 2 == 0) else "odd" ]
print(lst3)