Range Operation pre-PEP

Douglas Alan nessus at mit.edu
Fri May 11 00:17:36 CEST 2001

Ben Hutchings <ben.hutchings at roundpoint.com> writes:

> Lists also have count() and index() methods, which tuples do not.
> Doesn't this suggest a difference in intended purpose to you?

I also see that tuples support "in" and "+" and "*" and slicing and
len() and min() and max().  In light of this, it seems that the fact
that they are missing count() and index() should only been seen as an
unfortunate oversight.

>>> Tuples are like data structures or product types in other
>>> languages, except that their types and fields are nameless.
>>> Comprehensions work with a variable number of homogeneous values,
>>> so they produce lists.

> > filter() on a tuple returns a tuple.  The length of the tuple cannot
> > be known in advance.

> Presumably filter() only requires its argument to be a sequence.

Yes, if its sequence argument is a tuple, then it returns a tuple.  If
you were right, you should never want to run filter on a tuple, and if
you were so foolish to use filter() on a tuple, it should return a
list to show you the errors of your ways.  Or actually, tuples
shouldn't be sequences at all, since you should never treat a tuple as
a sequence, rather than just as a record.


More information about the Python-list mailing list