<div dir="ltr"><div class="gmail_quote">On Fri, Apr 22, 2011 at 12:42 PM, Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On Fri, Apr 22, 2011 at 7:59 PM, cool-RR <<a href="mailto:cool-rr@cool-rr.com">cool-rr@cool-rr.com</a>> wrote:<br>
> Here's an idea that would have helped me today while coding. Allow something<br>
> like this:<br>
>     ('blue', 'red', 'orange' if some_condition, 'green')<br>
> So 'orange' is included in the tuple only if `some_condition` evaluates to<br>
> `True`. This could be applied to list literals, tuple literals, set<br>
> literals, and possibly dict literals, though the latter might be too clunky.<br>
> I expect this to be rejected, but I really couldn't think of an elegant way<br>
> to achieve the same thing with existing syntax.<br>
<br>
</div></div>colours = 'blue red orange green'.split()<br>
if not some_conditions:<br>
    colours.remove('orange')<br>
<br>
There are lots of options, but most of them start by not using a tuple<br>
for a variable length sequence of like items.<br>
<br>
Cheers,<br>
Nick.</blockquote><div><br></div><div>I see. It's about as elegant as the other suggestions. And it's pretty annoying to use a list when I really wanted to use a tuple. Yeah, I can convert it to a tuple at the end, but that's just making it more verbose.</div>
<div><br></div><div><br></div><div>Ram.</div></div>
</div>