For review: PEP 308 - If-then-else expression
Greg Ewing (using news.cis.dfn.de)
me at privacy.net
Mon Feb 10 21:34:23 EST 2003
Andrew Dalke wrote:
> Part of the reason it
> hasn't been a problem is that few people do
> [x, y for x in list1 for y in [for z in spam] if x*y > 9.801]
Assuming you meant
[x, y for x in list1 for y in [z for z in spam] if x*y > 9.801]
the nested LC in there is redundant; this is equivalent to
[x, y for x in list1 for y in spam if x*y > 9.801]
I'm not sure, but it may even be a theorem that any nested
LC can be re-written as a non-nested LC by pulling all the
loops out to the top level and combining the target expressions
appropriately.
--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
More information about the Python-list
mailing list