What is a list compression in Python?
r.grimm at science-computing.de
Wed Jan 20 07:39:11 CET 2010
you can also look at list comprehension as syntactic sugar for the
functions map and filter. The two functions from the functional world
can be expressed in a comprehensive way with list comprehension.
>>> [x**2 for x in range(10) ] == map ( lambda x: x*x, range(10))
>>> [ x for x in range(10) if x%2 == 0 ] == filter ( lambda x: x%2 == 0 , range(10))
More information about the Python-list