Range Operation pre-PEP
ben.hutchings at roundpoint.com
Thu May 10 19:11:52 EDT 2001
Douglas Alan <nessus at mit.edu> writes:
> 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().
OK, you're right.
> In light of this, it seems that the fact that they are missing
> count() and index() should only been seen as an unfortunate
Based on the above - yes.
I'd be happier if tuples only supported len() though - because
this large overlap in tuple and list capabilities means that it's
less obvious which is a good choice for some particular purpose.
> >>> 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.
Well I think it should do that. Oh well.
> 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.
It's necessary to treat tuples generically sometimes, so they need to
Any opinions expressed are my own and not necessarily those of Roundpoint.
More information about the Python-list