Mar-26-2018, 03:08 AM
i would like to iterate over an iterator and then deal with it (the iterator itself), such as return it, in its incomplete (not iterated all the way) state. what i have been doing is making it into a list (using comprehension as i have found that some iterator classes "leak" through a list() call), popping elements as they are used, and using the incomplete list:
can i duplicate/replicate a generator part way through it doing its generating thing?
... mylist = [x for x in myiter] while mylist: thing = mylist.pop(0) result = testit(thing) if result: return mylist, result, thing ...i am looking for how i might do:
... for thing in mylist: result = testit(thing) if result: return ...so the big question is: is there a way to get (and pass along like return) the iterated state of any iterator? anything that can be iterated has to be storing that iteration state somewhere. is that accessible?
can i duplicate/replicate a generator part way through it doing its generating thing?