List comprehensions

Dan Schmidt dfan at harmonixmusic.com
Tue Dec 21 09:28:38 EST 1999


mlh at vier.idi.ntnu.no (Magnus L. Hetland) writes:

| Dan Schmidt <dfan at harmonixmusic.com> writes:
| 
| > mlh at vier.idi.ntnu.no (Magnus L. Hetland) writes:
| [...]
| > You know, I'm only half kidding when I say that the syntax for that
| > second type of loop should be
| > 
| >     P = [(x, y) for x in X while y in Y]
| 
| It's not that bad :)
| 
| However - it has a temporality to it that I don't think fits the
| sentence... I think "for all xs in X and ys in Y, do something"
| is quite standard english, yet "for all xs in X while ys in Y, do
| something" sounds a bit silly...

But you might actually say "for all x in X, while at the same time y
traverses over Y".  In fact, the syntax for it actually popped into my
head (from English usage), before I noticed that it could actually
work, since 'while' is a reserved word.

-- 
Dan Schmidt | http://www.dfan.org



More information about the Python-list mailing list