for in sequence problem... possible new operator to add to python

John J. Lee jjl at pobox.com
Fri Jul 11 03:26:53 CEST 2003


Peter Hansen <peter at engcorp.com> writes:

> sismex01 at hebmex.com wrote:
> > 
> > > From: Peter Hansen [mailto:peter at engcorp.com]
> > > When you iterate over a dict in recent versions of Python, you
[...]
> Sorry, perhaps I should stop using the term "iterate" for its
> more widely known generic meaning of visiting each item in a 
> sequence one at a time, and restrict my usage only to those
> cases where in Python I'm talking about an actual "iterator"
> object.
> 
> ("Iterate" was a very general term... it would be a shame if
> one could no longer use it as such.)

I think you're correct even in the strict Python sense of the word
'iteration'.  Objects (eg. dicts and lists) that are not themselves
iterators can still support iteration.  Section 2.2.5 from the 2.2
library reference:

   Python defines several iterator objects to support iteration over
   general and specific sequence types, dictionaries, and other more
   specialized forms. ...


John




More information about the Python-list mailing list