List vs tuples

John Roth newsgroups at jhrothjr.com
Thu Apr 8 19:14:58 EDT 2004


"Roy Smith" <roy at panix.com> wrote in message
news:roy-BDDD71.17205008042004 at reader1.panix.com...
> "John Roth" <newsgroups at jhrothjr.com> wrote:
> > A list is a data structure that is intended to be used with
> > homogenous members; that is, with members of the same type.
>
> There's really nothing about a list which makes it more suitable for
> homogeneous elements than a tuple.  It's true that people do tend to
> think tuple when they want a mixed collection of objects, but there's
> nothing in the language semantics which makes that so.
>
> I've written lots of code which parses data files.  If you've got a
> sequence of arbitrary type objects, the easiest way to process them is
> often to read them sequentially and append them to a list.  I don't see
> anything wrong with that.  For example, I once had to write some code
> which parsed SQL statements that looked something like:
>
> insert into foo values (1, 2, 'foo', 3.14, 'bar', 4, 5, 'baz', ...);
>
> There were a total of about 30 items of mixed type (strings, integers,
> and floats) in the ()'s.
>
> One of the really nice things about Python (vs. C++ or Java) is that
> you're not bound by the tyranny of static typing.  This is a perfect
> example of how this makes life so simple.

This is perfectly true, but that's the intention. Guido says
so himself. Lots of people either don't believe him, or
don't understand him.

If you think of it this way, the "quirks" become understandable:
it makes no sense to append something to the end of a c type
struct, for example.

John Roth





More information about the Python-list mailing list