I have a generator that produces a list of objects of two (let’s call them) kinds, e.g. a flag value:
import random
def ones_and_zeros_generator():
while True:
yield random.randint(0, 1)
Is there a way to pass it into another generator function to get two generators, one for the 0
s from the first generator, and one for the 1
s?
def my_other_generator(g):
...
ones_and_zeros = my_ones_and_zeros_generator()
ones, zeros = split_ones_and_zeros(ones_and_zeros)
for one in ones:
print('Another one')