[Python-Dev] re: for in dict (user expectation poll)

Greg Wilson gvwilson@ca.baltimore.com
Tue, 6 Feb 2001 12:28:59 -0500


> On Tue, 6 Feb 2001, Greg Wilson wrote:
> > Even after being shown half-a-dozen
> > examples of Python for loops, many of them write:
> > 
> >     for i in someSequence:
> >         print someSequence[i]
> > 
> > in their first exercise.

> Ka-Ping Yee:
> Amazing (to me).  Thank you for this data point; it's news to me.

Greg Wilson:
To be fair, these are all people with some previous programming
experience --- I suspect (no proof) that Fortran/C/Java have
trained them to think that iteration is over index space, rather
than value space.  It'd be interesting to check the intuitions
of students who'd been raised on the C++ STL's iterators, but I
don't think that'll ever be possible --- C++ seems to be dropping
out of the undergrad curriculum in favor of Java.

By the way, I do *not* think this is a knock-down argument against
your proposal --- it's no more of a wart than needing the trailing
comma in singleton tuples like "(3,)".  However:

1. Special cases make teaching harder (he said, repeating the
   obvious yet again).

2. I expect that if it was added, the "traditional" for-loop syntax
   would eventually fall into disfavor, since people who want to
   write really general functions over collections would have to
   use the new syntax.

Thanks,
Greg

p.s. in case no-one has said it, or I've missed it, thanks very
much for putting the PEP together so quickly, and for bringing
so many of the issues into focus.