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

Carl M. Johnson cmjohnson.mailinglist at gmail.com
Fri Apr 22 12:55:43 CEST 2011


On Fri, Apr 22, 2011 at 12:52 AM, Andre Engels <andreengels at gmail.com> wrote:
> On Fri, Apr 22, 2011 at 12:48 PM, cool-RR <cool-rr at cool-rr.com> wrote:
>
>> 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.
>
> But why do you want to have a tuple? A list is the logical Python
> translation of this kind of semantics.

Exactly. Ignoring memory/performance differences, the semantic reason
to use a tuple instead of a list is that you have group of things _and
their ordering matters_. If you can arbitrarily omit some items in the
sequence, it's not a tuple; it's a list. (Or maybe even a set.)



More information about the Python-ideas mailing list