[Python-3000] Set literal

Andrew McNabb amcnabb at mcnabbs.org
Sat Feb 2 18:36:38 CET 2008


On Sat, Feb 02, 2008 at 11:16:16AM +0900, Stephen J. Turnbull wrote:
> Greg Ewing writes:
> 
>  > Also, if generator expressions had come first, we
>  > would probably never have gotten list comprehensions.
> 
> I don't understand.  A list comprehension is for when you know you're
> going to want to work with the whole list.  Similarly (even more so)
> for dictionary comprehensions.  List comprehension can be defined in
> terms of a genexp, of course, but ISTM it's a worthwhile addition to
> the language in its own right.

I think Greg was just pointing out that with generator expressions, you
can write:

>>> lst = list(x**2 for x in xrange(10))
>>>

which would make it less necessary to the equivalent syntax:

>>> lst = [x**2 for x in xrange(10)]
>>>


-- 
Andrew McNabb
http://www.mcnabbs.org/andrew/
PGP Fingerprint: 8A17 B57C 6879 1863 DE55  8012 AB4D 6098 8826 6868
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-3000/attachments/20080202/90433ca9/attachment.pgp 


More information about the Python-3000 mailing list