PEP 308: Pep Update
Sheila King
usenet at thinkspot.net
Thu Feb 27 15:56:10 EST 2003
On Thu, 27 Feb 2003 19:10:06 +0100, "Anders J. Munch"
<andersjm at dancontrol.dk> wrote in comp.lang.python in article
<3e5e5441$0$16156$edfadb0f at dread11.news.tele.dk>:
> Yes. And that makes list comprehensions the most confusing Python
> construct there is. Not only doesn't it read left to right, it
> doesn't even read right to left either.
>
> Until I tried it, I fully expected
>
> [x*y for x in (1,2) for y in (-1,+1)]
>
> to produce
>
> [-1, -2, 1, 2]
I really do love the list comprehensions, myself. They are handy for a lot
of the email header and filtering type of scripts that I write.
I didn't find the example you posted confusing at all. It's just a nested
for-loop.
>>> [x*y for x in (1,2) for y in (-1,+1)]
[-1, 1, -2, 2]
>>> mylist = []
>>> for x in (1,2):
for y in (-1, +1):
mylist.append(x*y)
>>> mylist
[-1, 1, -2, 2]
>>>
--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/
More information about the Python-list
mailing list