On 14 Dec 2006 11:24:04 GMT, Nick Maclaren <[EMAIL PROTECTED]> wrote:
>
> Why doesn't the tuple type have an index method?  It seems such a
> bizarre restriction that there must be some reason for it.  Yes,
> I know it's a fairly rare requirement.

It's because, philosophically, a Python tuple isn't just a read-only list.

Lists are for homogeneous data, all entries being of the same 'type'.
('Type' here doesn't refer to class or anything like that - just
conceptual type - what kind of thin g it is.) So, you can infer no
semantic meaning from an items position in the list. Sorting makes
sence,m and does looking though a list to find something - hence
index().

A tuple, on the other hand, is heterogeneous. The fact that an item is
the nth item is a tuple *means* something. Sorting a tuple would make
no sense, even if it were possible, and you are supposed to know where
in the tuple things are, so it makes no sense to search for it.

-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to