Tuple question

Alex Martelli aleaxit at yahoo.com
Sat Sep 4 11:00:30 CEST 2004


Donn Cave <donn at u.washington.edu> wrote:
   ... 
> On the other hand, we normally use tuples for data that
> is meaningful only when it's intact.  The (key, value)

So by this argument len(t) should not work if t is a tuple...

I've never accepted the BDFL's explanations on what tuples are for; like
Python beginners I use them as immutable lists (to index into a
dictionary or be set members) and curse their lack of useful methods.

> pair that comes back from dict.items(), for example.  Each
> value may very well be a string, but the sequence is not
> homogeneous in the sense we're talking about, and index()
> is not useful.

Even for a pair I sometimes like to know if 42 is the key, the  value,
or neither.  index is handy for that... but not if the pair is a tuple,
only if it's a list.  Rationalize as you will, it's still a Python wart.

Pseudotuples with NAMED (as well as indexed) arguments, as modules stat
and time now return, may be a different issue.  Not sure why we never
made declaring such pseudotuples as usertypes as easy as it should be, a
custom metaclass in some stdlib module shd be enough.  But tuples whose
items can't be named, just indexed or sliced, just are not a good fit
for the kind of use case you and Guido use to justify tuple's lack of
methods, IMHO.


Alex



More information about the Python-list mailing list