removing list comprehensions in Python 3.0

John Roth newsgroups at jhrothjr.com
Sat Jul 9 11:38:57 EDT 2005


"Raymond Hettinger" <python at rcn.com> wrote in message 
news:1120919382.609886.62680 at g14g2000cwa.googlegroups.com...
> 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.

I was wondering about what seemed like an ill-concieved rush to
make everything an iterator. Iterators are, of course, useful but there
are times when you really did want a list.

John Roth
>
>
> Raymond Hettinger
> 




More information about the Python-list mailing list