I came across everything related to iterators today and there are still some things I don't understand. I'm still a Python beginner but I'll try to explain the best I can.
- I understand the difference between an iterable and an iterator. However, couldn't we just simply implement the
__next__method on a list and somehow make it to go back tolist[0]whenStopIterationwas raised? Wouldn't that free up some memory as iterators also allocate space in memory? What's really the reason for iterators to exist? - I also understand the difference between a generator and a list, for example. Also, there is a type of iterator for each object (e.g
range_iterator). How aregenerator_iteratorsdifferent from other iterator objects? Are they added values on the fly?