Tuple question

Peter Hansen peter at engcorp.com
Thu Sep 2 21:35:39 CEST 2004

Gandalf wrote:

> This is from that thread:
>> Note that while .index() makes sense for some sequences,
>> such as strings and lists, it doesn't make sense for the
>> way in which tuples are "supposed to be used", which is
>> as collections of heterogeneous data and not usually as
>> simply read-only lists. 
> Why it is not useful to have an index() method for collections of 
> heterogeneous data?

Because you will already know where the different items or
types of items are in the sequence.  If you don't, it's
probably not heterogeneous data using the definition that
is being used by those saying that tuples are not just
immutable lists.

> Suppose, you have big amount of data stored in tuples (for using less 
> memory).

Why do you think tuples use significantly less memory than lists?
As far as I know, they don't.  (They do use less, but if you are
really talking about huge amounts of data such that you would
be trying to optimize in this way, then the amount that they use
is not *significantly* less.)

> You may want to extract slices from the tuploes from a given index 
> determined by an object.
> This is just an example, however it is quite realistic (e.g. using 
> tuples instead of lists
> because there is a huge amount of static data that you need to access 
> quickly).

Actually, it's realistic but unwise and a waste of time.  Use lists,
that's what they were meant for...


More information about the Python-list mailing list