I have a dummy example of an iterator container below (the real one reads a file too large to fit in memory):
class DummyIterator:def __init__(self, max_value):self.max_value = max_valuedef __iter__(self):for i in range(self.max_value):yield idef regular_dummy_iterator(max_value):for i in range(max_value):yield i
This allows me to iterate over the value more than once so that I can implement something like this:
def normalise(data):total = sum(i for i in data)for val in data:yield val / total# this works when I call next()
normalise(DummyIterator(100))# this doesn't work when I call next()
normalise(regular_dummy_iterator(100))
How do I check in the normalise function that I am being passed an iterator container rather than a normal generator?