Apr-30-2019, 02:21 AM
Iterators are objects, just like everything else:
>>> x = list(range(10)) >>> it = iter(x) >>> for a in it: ... print(a) ... if a == 4: ... break ... 0 1 2 3 4 >>> for b in it: ... print(b) ... 5 6 7 8 9However, I don't believe you can make iterators go backwards. You could recreate the iterator. You could also make a wrapper class for an iterator that keeps track of what was already iterated over in a stack, and then call it back somehow.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures