How to create linked list automatically
Simon Brunning
simon at brunningonline.net
Mon Dec 19 15:51:39 EST 2005
I haven't the time (or inclination) to sort out all your problems
here, but one thing jumps out at me:
On 12/19/05, Shahriar Shamil Uulu <shamilsons at yahoo.com> wrote:
> class Node:
> def __init__(self,name=None,next=None):
> self.name=name
> self.next=next
>
> def __str__(self):
> return str(self.name)
Your Node classes str() prints the instances self.name attribute,
which is set by an optional named argument on the initialiser...
> w=[]
> for i in range(10):
> node=Node(i)
... but you aren't providing this argument when you build your Node objects...
> am trying to connect them, but when i try to print the connection i
> got this:
> ===================================================================
> >>>
> connection done
> None
So it's hardly surprising that printing your Node objects always prints "None".
--
Cheers,
Simon B,
simon at brunningonline.net,
http://www.brunningonline.net/simon/blog/
More information about the Python-list
mailing list