tuple.index()

Nick Maclaren nmm1 at cus.cam.ac.uk
Wed Dec 20 06:31:45 EST 2006


In article <458919DD.40901 at cosc.canterbury.ac.nz>,
greg <greg at cosc.canterbury.ac.nz> writes:
|> 
|> >     It does explain why you think of lists as homogeneous, but the
|> > analogy doesn't hold water on closer inspection.  There doesn't seem
|> > to be ANYTHING in the specification or implementation that assumes
|> > lists are homogeneous.
|> 
|> Then what do you think is suggested by the fact
|> that lists have an index() method but tuples don't?

Eh?  Nothing relevant to homogeneity, to be sure.  See the Library
reference, 2.3.3.  It starts by saying "Comparison operations are
supported by all objects." and the first paragraph after the table
says that == is defined to return False for different types (except
numeric and string).  2.3.6 (Mutable Sequence Types) says that index
returns the smallest value such that == returns True.

So index finds a match among compatible types.  That is an old
specification of searching heterogeneous lists that I have been
using for over 30 years - I can't now remember which languages
include it.

What's the problem?

|> That's how this whole discussion got started --
|> someone wanted an explanation of why that is so.
|> The explanation is that tuples and lists were
|> designed for different use cases.

The problem is that the homogeneity argument is irrational (which
does NOT necessarily mean either wrong or undesirable), IS NOT
DOCUMENTED IN THE REFERENCES, and Python is not generally irrational.
My mental model of Guido is that he thinks fairly rationally.  Python
isn't Perl or C, after all.

|> You don't *have* to use them that way, but if
|> you use them differently, you're on your own
|> and can't complain if they don't have all the
|> features you want.

Which is tantamount to saying that Python doesn't support mutable
heterogeneous sequences, even though they are not locked out.  That
is more than just odd - it is almost unbelievable.  They are a very
basic data structure, after all!


Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email:  nmm1 at cam.ac.uk
Tel.:  +44 1223 334761    Fax:  +44 1223 334679



More information about the Python-list mailing list