General question about Python design goals

Antoon Pardon apardon at forel.vub.ac.be
Thu Dec 1 11:25:59 CET 2005


On 2005-12-01, Fredrik Lundh <fredrik at pythonware.com> wrote:
> Mike Meyer wrote:
>
>> So why the $*@& (please excuse my Perl) does "for x in 1, 2, 3" work?
>
> because the syntax says so:
>
>     http://docs.python.org/ref/for.html
>
>> Seriously. Why doesn't this have to be phrased as "for x in list((1,
>> 2, 3))", just like you have to write list((1, 2, 3)).count(1), etc.?
>
> because anything that supports [] can be iterated over.

This just begs the question. If tuples are supposed to be such
heterogenous sequences, one could indeed question why they
support [].

And even if good arguments are given why tuples shouls support
[], the fact that the intention of tuples and list are so
different casts doubts on the argument that supporting []
is enough reason to support iteration.

One could equally also argue that since iteration is at the heart
of methods like index, find and count, that supporting iteration
is sufficient reason to support these methods.

-- 
Antoon Pardon



More information about the Python-list mailing list