tuples, index method, Python's design

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Wed Apr 11 10:58:53 EDT 2007


On Wed, 11 Apr 2007 13:13:20 +0000, Antoon Pardon wrote:

>> Lists are designed for sequences of homogeneous items, e.g.:
>>
>> L = [1, 2, 4, 8, 16, 32]
>> while tuples are designed to be more like structs or records, with
>> heterogeneous items, e.g.:
>>
>> T = ("Fred", 32, 12.789, {}, None, '\t')
> 
> I think you are confused. 

Anything is possible.


> Last time I heard this homogeneous items stuf,
> it had nothing to do with the types being the same. They were homogeneous
> because they somehow belonged together and heterogeneous because they
> just happened to live together. Similarity of type played no part in
> calling the data homogeneous or heterogeneous.

Nevertheless, regardless of whether the items have the same type or
different types, you don't need an index method for heterogeneous items.

Like I said, think of a tuple as a struct. Even if the fields of the
struct all have the same type, there is little reason to ever ask "which
field has such-and-such a value?".

Anyway, that's was the reasoning. As I've said, tuples do double-duty as
both immutable lists and struct-like objects. I wouldn't object to them
growing index and count methods -- but you won't see me volunteering to
write the code for that, because I don't care that much.

So how about it? All you people who desperately want tuples to grow an
index method -- will any of you donate your time to write and maintain the
code?



-- 
Steven.




More information about the Python-list mailing list