0

List comprehension

What is benefit of using list comprehension?

30th Jan 2017, 9:34 AM
Mukul P Singh
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.
30th Jan 2017, 9:38 PM
Amaras A
Amaras A - avatar
+ 1
Shorthand writting... often more readable code ( but not always ^^ )
31st Jan 2017, 8:42 AM
visph
visph - avatar