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

Sean Ross sross at connectmail.carleton.ca
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
y's
like
     [x,y,x,..](as it should),
or
    [[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
idea
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
comprehension,
and it would catch a persons attention more forcefully than regular
parenthesis.
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]
<wink>
Sean






More information about the Python-list mailing list