human
What is a code to 13 given the following:
13. Generators with State"
Please write code following the instructions in jupyter notebook style.
assistant
#Here is code to 13.

# To expose state available at each step of iteration, use a classs that implements __iter__()
class countingiterator:
    def __init__(self, items):
        self.items=items
    def __iter__(self):
        self.clear_count()
        for item in self.items:
            self.count+=1
            yield item
    def clear_count(self):
        self.count=0

foo = countingiterator(["aaa","bbb","ccc"])

for i in foo:
    print("{}:{}".format(foo.count, i))