[thing for thing in list_of_things]
[thing for thing in list_of_things if thing.xyz...]
for example
It can also be used in dict, inside {}
iterate dict
for k,v in d.items()
Now x is {1: 'a'}
set comprehensions
They are also similar to list comprehensions. The only difference is that they use braces {}. Here is an example:
http://blog.teamtreehouse.com/python-single-line-loops
https://docs.python.org/3.6/tutorial/datastructures.html search List Comprehensions
No comments:
Post a Comment