Thursday, August 24, 2017

python list comprehensions - Single Line For Loops

List comprehensions provide a concise way to create lists.
[thing for thing in list_of_things]
[thing for thing in list_of_things if]

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: search List Comprehensions

No comments:

Post a Comment