tuple.index()
Fredrik Lundh
fredrik at pythonware.com
Thu Dec 14 07:21:04 EST 2006
Nick Maclaren wrote:
> My understanding of the difference between a tuple and a list is
> PRECISELY that the former is immutable and the latter mutable.
while tuples can be used as "frozen lists", that's definitely not what
they are, from a design perspective.
just like in math [1], a Python tuple is a heterogeneous sequence where
the position implies type and usage. in contrast, a list is a homo-
geneous collection where all the items are "the same" in some sense,
no matter where they are. if you sort or otherwise reorder a list
of things, it's still a list of the same things. if you sort a tuple,
you'll break it.
in other words, you're supposed to know what the individual items are in
a tuple; if you feel the need to search for things by value in a tuple,
you're using the wrong container type.
</F>
1) http://en.wikipedia.org/wiki/Tuple
More information about the Python-list
mailing list