Junior — Senior
Implementation of a custom iterator in Python
livecode
Task condition
It is necessary to write a custom iterator class that will sequentially return elements of the given list.
class MyIterator:
def __init__(self, data):
# TODO
def __iter__(self):
# TODO
def __next__(self):
# TODO
The class should support the iteration protocol: the __iter__ method returns an iterator object, and __next__ yields the next element of the list, raising StopIteration at its end.