LLD - Behavioral Design Patterns — Part 1
Given this iterator implementation in Python, identify the bug:
class BuggyIterator:
def __init__(self, data):
self.data = data
self.index = 0
def __iter__(self):
return self
def __next__(self):
if self.index <= len(self.data):
result = self.data[self.index]
self.index += 1
return result
else:
raise StopIterationWhat is the cause of the error when iterating?
