Using and Implementing iterators with classes such as linked lists
Aahz
aahz at pythoncraft.com
Tue Dec 2 21:19:35 EST 2003
In article <Xns94445A429CFEduncanrcpcouk at 127.0.0.1>,
Duncan Booth <duncan at rcp.co.uk> wrote:
>
>def __iter__(self):
> def iterate(current):
> while current.next is not None:
> next = current.next
> yield current
> current = next
> return iterate(self)
Huh? Why the extra function and complexity?
def __iter__(self):
current = self
while current is not None:
yield current
current = current.next
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
Weinberg's Second Law: If builders built buildings the way programmers wrote
programs, then the first woodpecker that came along would destroy civilization.
More information about the Python-list
mailing list