tuples, index method, Python's design

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Wed Apr 11 09:30:49 EDT 2007


In <slrnf1pnng.klv.apardon at rcpc42.vub.ac.be>, Antoon Pardon wrote:

> On 2007-04-11, Steven D'Aprano <steve at REMOVE.THIS.cybersource.com.au> 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. 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.

Then you are confused.  The typical use case for tuples are database
records.  The columns in the table can have completely different types but
the values in a row, represented as a Python tuple, of course belong
together.

The homogeneous objects in lists must not be of the same type but share
some behavior so it makes sense to apply some operation on all the
elements.  For example get the length of each item or sum them all up.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list