Neil Cerutti wrote: > On 2007-12-10, Duncan Booth <[EMAIL PROTECTED]> wrote:
>> def test(): >> ll = LinkedList([random.randint(1,1000) for i in range(10)]) >> >> for el in ll: >> if el.value%2==0: >> ll.delete(el) >> >> print [el.value for el in ll] >> >> >> if __name__=='__main__': >> test() >> >> Support for deleting elements other than the current one, and >> insertBefore/insertAfter methods is left as an exercise. > > Making an object its own iterator [works] for files, but not for a > container. After the deletions, you can never iterate again. Look at the test code again -- there is a second iteration after the deletions (the list comprehension). However, you will get into trouble if you try to run two simultaneous iterations over the same LinkedList, so there is room for another exercise ;) Peter -- http://mail.python.org/mailman/listinfo/python-list