Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #goal is to push 3 lines into one line, append elements to new list if they are even
- #what I would typically do:
- #a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
- #bList = []
- #for i in a:
- # if i % 2 == 0:
- # bList.append(i)
- #
- #print(bList)
- #what python can do with list comprehension:
- print([i for i in [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] if i % 2 == 0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement