tuple.index()

Georg Brandl g.brandl-nospam at gmx.net
Thu Dec 14 10:28:52 EST 2006


Nick Maclaren schrieb:
> In article <1166106278.106832.278240 at n67g2000cwd.googlegroups.com>,
> "Glenn Hutchings" <zondo42 at googlemail.com> writes:
> |> Fredrik Lundh wrote:
> |> 
> |> > if you don't want to understand the design, nobody can force you.  but arguing
> |> > that the people behind the design "don't get it" isn't very practical.
> |> 
> |> I'm not arguing that at all.  What I'm saying is that from the
> |> perspective of someone not interested in design issues, it seems like
> |> an omission for tuples to be missing the non-modifying methods that
> |> lists have.
> 
> And, from the perspective of someone VERY interested in design issues,
> from the viewpoint of program validation (a.k.a mathematical models,
> a.k.a. 'program proving' a.k.a. 'software engineering') it also seems
> like one!
> 
> If lists are intended to be homogeneous, then they should be checked
> for that, and an exception raised when an attempt is to make them
> non-homogeneous.  At least as a Python checking option.

There you have the "consenting adults" philosophy again: You know what lists
are for, so you can use them for it. You can also use them for something else,
but in that case it's moot to complain about missing features.

> If tuples are intended to be bags, then it makes no sense to allow
> them to be subscripted OR indexed.  Mathematically, 'x = a[i]' and
> 'i = a.index(x)' have dual properties - and are true duals if you
> include the constraint of no duplicate elements.

You're describing sets. Tuples are not sets. Sets are not indexable and have
unique elements.

Indexing is the *vital* point of tuples. They are an ordered collection of
values, and you are supposed to know which data is found at which index.
Don't tell me that tuples in maths are sets.

For a mathematical example, take

A = { (x,y) : 0 < x < 1, 0 < y < 1 }

Here, (x,y) is a 2-tuple, and you know that at index 0 there's the x-coordinate
of a point contained in the square A, and at index 1 there's the y-coordinate.

Georg



More information about the Python-list mailing list