Reputation: 11
I am trying to create a doubly linked list..Here is my code but when i run it it is giving me this output: <__main__.DLList object at 0x10269d588>
. I don't know how to fix this.
Upvotes: 0
Views: 191
Reputation: 881605
You have not defined special methods __str__
or __repr__
, so they default to the display you appear to dislike. To get your own display, define such methods.
For example (in the body of DLList
) add:
def __str__(self):
result = []
cur = self.head
while cur is not None:
result.append(repr(cur.data))
cur = cur.next_node
return ', '.join(result)
this uses no starting or ending markers, comma separation, and repr (rather than str) for each item -- of course, you can tweak each of these design choices (but beware: using str in lieu of repr can create very confusing displays, identical for lists that are actually quite different).
Upvotes: 1