lists v. tuples

Ninereeds stephenhorne100 at aol.com
Mon Mar 17 15:35:49 CET 2008


On Mar 17, 1:31 pm, Duncan Booth <duncan.bo... at invalid.invalid> wrote:

> A common explanation for this is that lists are for homogenous
> collections, tuples are for when you have heterogenous collections i.e.
> related but different things.

I interpret this as meaning that in a data table, I should have a list
of records but each record should be a tuple of fields, since the
fields for a table usually have different forms whereas the records
usually all have the same record layout.

Makes sense, but not exactly *because* of the homogenous/heterogenous
thing but rather because a record is smaller than a table, and a
records component fields are more closely bound together than the
records in a table.

In short, adding, removing and overwriting records are essential
operations (though Haskell programmers might disagree). Any
modifications to records themselves can practically be handled as
replacing one complete tuple with another.

As a final note, I tend to implement tables as either lists of
dictionaries, or lists of class instances. That way my fields are
named. Its better in maintenance terms if I need to add new fields to
the tables later on.



More information about the Python-list mailing list