Have tried to create a python Single Linked list , but i'm not able to create a iterator. Here is my code :
class LinkedList:
def __init__(self):
self._head=self
self._tail=self
self._size=0
def __iter__(self):
print 'Calling Iterator\n\n'
_ListIterator(self._head)
class ListObj:
def __init__(self,value):
self._data=value
self._pointingTo=None
class _ListIterator:
def __init__(self,listHead):
LIST=None
self._curNode=listHead
print dir(self._curNode)
def __next__(self):
if self._curNode._pointingTo is None:
raise StopIteration
else:
item=self._curNode._data
self._curNode=self._curNode._pointingTo
return item
This iterator is failing by throwing an error as
TypeError: __iter__ returned non-iterator of type 'NoneType'