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

Sean Ross sross at
Mon Feb 10 03:38:12 CET 2003

True enough.

And things like:
    [[x if C else y] for x,y in pairs]
could compound peoples confusion...
you might wonder whether that expression returns some combination of x's and
     [x,y,x,..](as it should),
    [[x],[y],[x],...] (as you might expect)
So, yeah, I guess square brackets should be left out...

I don't mind
    (x if C else y)
in which case, you could have:
    [(x if C else y) for x, y in pairs]
though I think parentheses often look like they might be optional, when in
this case
we might be proposing that they be required. And then there was the other
I threw out, namely:
    |x if C else y|
which would allow for:
   [ |x if C else y| for x,y in pairs]
This would certainly distinguish the if expression from a list
and it would catch a persons attention more forcefully than regular
Still, I don't much care for it. I think regular parentheses, or none, are
more likely
to be acceptable.

And then there's always:
    [(when C: x else: y) for x, y in pairs]

More information about the Python-list mailing list