Iterator - what I am missing
Steven Taschuk
staschuk at telusplanet.net
Thu Aug 14 21:03:18 EDT 2003
Quoth I:
['for x in iterable: mung(x)' works like...]
> iterator = iter(iterable) # get iterator object
> try:
> while True:
> x = iterator.next() # call its .next() method repeatedly
> mung(x)
> except StopIteration:
> pass
A wee braino in the above. Should be
iterator = iter(iterable)
while True:
try:
x = iterator.next()
except StopIteration:
break
else:
mung(x)
--
Steven Taschuk staschuk at telusplanet.net
"Telekinesis would be worth patenting." -- James Gleick
More information about the Python-list
mailing list