Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # list_comprehension.py -- basically a for loop that returns a list
- # the long code:
- mylist = []
- for x in [1,2,3]:
- mylist.append("x:" + str(x))
- print mylist
- # ["x:1", "x:2", "x:3"]
- # the short code:
- print ["x:" + str(x) for x in [1,2,3]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement