removing list comprehensions in Python 3.0

Raymond Hettinger python at rcn.com
Sat Jul 9 16:29:42 CEST 2005


In all probability, both list comprehensions and generator expressions
will be around in perpetuity.  List comps have been a very successful
language feature.

The root of this discussion has been the observation that a list
comprehension can be expressed in terms of list() and a generator
expression.   However, the former is faster when you actually want a
list result and many people (including Guido) like the square brackets.

After the advent of generators, it seemed for a while that all
functions and methods that returned lists would eventually return
iterators instead.  What we are learning is that there is a place for
both.  It is darned inconvenient to get an iterator when you really
need a list, when you want to slice the result, when you want to see a
few elements through repr(), and when you need to loop over the
contents more than once.


Raymond Hettinger




More information about the Python-list mailing list