List comprehension | Sololearn: Learn to code for FREE!

0

List comprehension

What is benefit of using list comprehension?

1/30/2017 9:34:42 AM

Mukul P Singh

2 Answers

New Answer

+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 ^^ )