What's do list comprehensions do that generator expressions don't?
Ville Vainio
ville at spammers.com
Mon Apr 25 16:33:48 EDT 2005
>>>>> "Jeremy" == Jeremy Bowers <jerf at jerf.org> writes:
Jeremy> On Sun, 24 Apr 2005 22:59:12 -0700, Robert Kern wrote:
>> Never. If you really need a list
>>
>> list(x*x for x in xrange(10))
>>
>> Sadly, we can't remove list comprehensions until 3.0.
Jeremy> Why "remove" them? Instead, we have these things called
Jeremy> "comprehensions" (which, now that I say that, seems a
Jeremy> rather odd name), and you can control whether they result
Jeremy> in a list or a generator with () or [].
Still, list comprehensions should be implemented in terms of genexps
to get rid of the LC variable that is visible outside the scope of the
LC.
Jeremy> should be relatively simple), it's not worth breaking that
Jeremy> code.
Well, the code that relies on the dangling variable deserves to break.
--
Ville Vainio http://tinyurl.com/2prnb
More information about the Python-list
mailing list