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

Nick Coghlan ncoghlan at email.com
Tue Jul 6 09:46:26 CEST 2004

Quoting "Michael P. Dubner" <dubnerm-news at mail.ru>:

> I'm not sure this kind of generalization is correct at all - list 
> elements are sorted, but dict's doesn't.
> Also accesses(myDict) might be misunderstood as accesses(myDict.keys()) 
> which is incorrect in general (because keys() not guaranteed to return 
> keys every time in same order).

One question I have is just what the use case is where one wants to iterate 
over the indices of a list, but _don't_ want to look at the values.

I can't think of a time where I've iterated over indices, without then having a 
container[index] written somewhere inside the loop.

And for that use case, we can now use:
  for index, item in enumerate(container): pass

I suppose a case where we're getting a more complicated slice than just the 
value corresponding to an index would qualify. But how many of these uses would 
also require more than just a simple sequential iteration over the indices?


Nick Coghlan
Brisbane, Australia

More information about the Python-Dev mailing list