Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. #goal is to push 3 lines into one line, append elements to new list if they are even
  2. #what I would typically do:
  3. #a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
  4. #bList = []
  5. #for i in a:
  6. # if i % 2 == 0:
  7. # bList.append(i)
  8. #
  9. #print(bList)
  10. #what python can do with list comprehension:
  11. 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