0
List comprehension
What is benefit of using list comprehension?
2 Answers
+ 1
Not having to do:
result = []
for each in something:
a = func(each)
result.append(a)
With a list comprehension, you just do:
result = [func(each) for each in something]
It also has the advantage of putting what is connected in the same logical line.
+ 1
Shorthand writting... often more readable code ( but not always ^^ )