[Python-Dev] PEP 276 (simple iterator for ints)

Andrew Koenig ark at acm.org
Sun Jul 4 17:13:01 CEST 2004

> IMO it would be clearer, and equally elegant, to write
> this as something like
>   for i in indices(myList):
>     ...
> which is easily accomplished with the aid of a suitable
> definition for indices(). No language changes needed.

I think that

for i in myList.keys():

would be even better, because it allow the same usage for dict and list.  Of
course that wouldn't generalize to other sequences that support len.

Incidentally, I've always liked Algol 68's loop syntax, which if I remember
right is something like this:

	[ for <id> ] [ from <expr> ] [ to <expr> ] [ by <expr> ]
         [ while <expr> ]  do <suite> od

So one would write

	for i to n do ... od

or even

	for i from 0 while <whatever> do ... od

which would loop while <whatever> is true and keep count of the iterations.

More information about the Python-Dev mailing list