[Tutor] Re: Linked List
Andrei
project5 at redrival.net
Fri Mar 4 19:17:06 CET 2005
Shitiz Bansal wrote on Fri, 4 Mar 2005 09:19:41 -0800 (PST):
> Any body has any idea on how to implement a linked
> list in python?
Perhaps like this:
>>> class node(object):
... def __init__(self, item, next=None):
... self.item = item
... self.next = next
>>> a = node('item a')
>>> b = node(3)
>>> c = node((3,4))
>>> d = node('last item')
>>> a.next = b
>>> b.next = c
>>> c.next = d
>>> mynode = a
>>> while mynode:
... print mynode.item
... mynode = mynode.next
item a
3
(3, 4)
last item
--
Yours,
Andrei
=====
Real contact info (decode with rot13):
cebwrpg5 at jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.
More information about the Tutor
mailing list