Edit (Added suggested methods):
def __len__(self):
"""
Returns the current size of the list. O(n), linear time
"""
current = self.head
count = 0
while current:
count += 1
current = current.next
return count
def __contains__(self,value):
"""
Returns True or False depending on whether an item with
node.value = value is in the list
"""
current = self.head
found = False
while current and not found:
if current.value == value:
found = True
return True
else:
current = current.next
if not current:
return False
def __bool__(self):
"""
Implements boolean check of the class
"""
if self.__len__() == 0:
return False
else:
return True
def __iter__(self):
"""
Creates an iterator. Returns itself.
"""
return self
def __next__(self):
"""
Provides the next entry to the iterator
"""
if not self.__current:
self.__current=self.head
raise StopIteration
else:
current = self.__current
self.__current=self.__current.next
return current