[Python-ideas] ('blue', 'red', 'orange' if something, 'green')

cool-RR cool-rr at cool-rr.com
Fri Apr 22 11:59:39 CEST 2011


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 could be applied to list literals, tuple literals, set
literals, and possibly dict literals, though the latter might be too clunky.

I expect this to be rejected, but I really couldn't think of an elegant way
to achieve the same thing with existing syntax.


Ram.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110422/c4ad17c8/attachment.html>


More information about the Python-ideas mailing list