[Python-ideas] ('blue', 'red', 'orange' if something, 'green')
Sturla Molden
sturla at molden.no
Fri Apr 22 19:41:11 CEST 2011
Den 22.04.2011 11:59, skrev cool-RR:
> Here's an idea that would have helped me today while coding. Allow
> something like this:
>
> ('blue', 'red', 'orange' if some_condition, 'green')
>
> So 'orange' is included in the tuple only if `some_condition`
> evaluates to `True`.
This means it should be legal to write
a = 'orange' if cond
which presumably should mean
if cond: a = 'orange'
It retains some symmetry with
a = 'orange' if cond else 'yellow'
Sturla
More information about the Python-ideas
mailing list