For review: PEP 308 - If-then-else expression

Andrew Koenig ark at
Sat Feb 8 19:37:50 CET 2003

AD> David Eppstein pointed out one, with

AD>    if i < 0:
AD>     col = None
AD>   else:
AD>     col = cols[i]

AD> which is nicely expressed as

AD>   col = cols[i] if i < 0 else None

Except that you flipped the conditions -- I think you meant to write

        col = None if i < 0 else cols[i]

or, probably better:

        col = cols[i] if i >= 0 else None

Andrew Koenig, ark at,

More information about the Python-list mailing list