* John Fouhy <[EMAIL PROTECTED]> [051113 12:16]: > On 14/11/05, Tim Johnson <[EMAIL PROTECTED]> wrote: > > Now if I assign a value to the iteritems method, as in > > it = s.iteritems() > > I get an object of <dictionary-iterator object at 0x407e3a40> > > and dir(it) shows that (it) has one public method - next(). > > Yep. The normal way to use an iterator is in a for loop. As soon as I saw the next() method, I recognized it from using a csv module ......
> So, if you've done 'it = s.iteritems()', you can then do: > > for key, value in it: > # do something with key, value > > Of course, normally you would cut out the assignment step: > > for key, value in s.iteritems(): > # do something with key, value > > When dealing with an iterator, a for loop is basically equivalent to this: > > it = s.iteritems() > while True: > try: > key, value = it.next() > except StopIteration: > break > # do something with key, value > > HTH! > > -- > John. > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor -- Tim Johnson <[EMAIL PROTECTED]> http://www.alaska-internet-solutions.com _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor