LLD - Behavioral Design Patterns — Part 1
Identify the error in this iterator implementation snippet:
class MyIterator:
def __init__(self, collection):
self.collection = collection
def hasNext(self):
return self.index < len(self.collection)
def next(self):
if self.hasNext():
element = self.collection[self.index]
self.index += 1
return element
else:
raise StopIteration()
What is missing that causes a runtime error?
