Heterogeneous lists

Hendrik van Rooyen mail at microcorp.co.za
Wed Aug 8 03:20:55 EDT 2007


"Gordon Airporte" <J,,,,r at fbi.gov>

> This is one of those nice, permissive Python features but I was 
> wondering how often people actually use lists holding several different 
> types of objects.

I do it all the time - I only use tuples when I _have_ to.

> It looks like whenever I need to group different objects I create a 
> class, if only so I can use more meaningful names than '[2]' for the items.

You don't have to be so array-minded.  You can write things like:

address = 2
individual_list[address]

this is easier to read and understand than:

individual_list[2]

and does the same thing.

I have found that the most useful data structure is a dict, 
or a dict of dicts. - almost an instant database.

- Hendrik






More information about the Python-list mailing list