Range Operation pre-PEP
Ben Hutchings
ben.hutchings at roundpoint.com
Thu May 10 15:27:50 EDT 2001
Douglas Alan <nessus at mit.edu> writes:
> Ben Hutchings <ben.hutchings at roundpoint.com> writes:
>
> > Douglas Alan <nessus at mit.edu> writes:
>
> > > Speaking of creeping-featurism, how come we have list comprehension,
> > > but not tuple comprehension? Seems inconsistent to me.
>
> > A list contains a variable number of homogeneous values, e.g. the
> > lines of a file. Lists are like arrays in other languages. A tuple
> > contains a fixed number of heterogeneous values where each element
> > has a distinct meaning e.g. (year, month, day) for a date.
>
> I think you have some other language in mind, rather than Python. In
> Python, the only semantic difference between a list and a tuple is
> that a tuple is immutable.
Lists also have count() and index() methods, which tuples do not.
Doesn't this suggest a difference in intended purpose to you?
> > 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.
<snip>
Presumably filter() only requires its argument to be a sequence.
--
Any opinions expressed are my own and not necessarily those of Roundpoint.
More information about the Python-list
mailing list