If I have an iterator foo
and a function progress
which progresses it some arbitrary amount (but with the guarantee that it will never raise StopIteration
), how do I keep calling progress
until foo
is empty?
It looks like iter([])
is truthy.
This is my best attempt:
from itertools import islice
import copy
# Let's say I can't touch this function.
def progress(xs):
islice(xs, 1) # or some other arbitrary value.
foo = iter(a_list)
while list(copy.copy(foo)): #
progress(foo)