For review: PEP 308 - If-then-else expression
Andrew Dalke
adalke at mindspring.com
Sat Feb 8 03:38:52 EST 2003
Aahz:
> You've put your finger on the reason I feel a stronger negative reaction
> to this than the listcomps. It seems rare to me that someone tries to
> directly transpose a for loop into a listcomp or vice-versa, but I think
> that'll be much more common with this.
And when that occurs, the for/if order is the same, as in
result = []
for x in data:
if x[0] > 5:
result.append(x[1])
which is mapped almost directly as
result = [x[1] for x in data if x[0] > 5]
The term out of order is the 'append' component, not the if.
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list