I'm using the answer(s) from here and here to check if my generator x
is empty.
from itertools import tee
def my_generator():
yield from range(100000000)
x = my_generator()
x, y = tee(x)
try:
next(y)
except StopIteration:
# x is empty do something
quit()
What will happen to the elements extracted from x
? can they be discarded ? or must be kept in memory for y
?
# now consume x entirely
for z in x:
print(x)
# how can y iterate over its objects ?
# will they have to reside in memory now ??