Is there a standard pythonic way of selecting a value from a list of provided iterators without advancing those that were not selected?
Something in the vein of this for two iterators (don't judge this too hard: it was quickly thrown together just to illustrate the idea):
def iselect(i1, i2, f):
e1_read = False
e2_read = False
while True:
try:
if not e1_read:
e1 = next(i1)
e1_read = True
if not e2_read:
e2 = next(i2)
e2_read = True
if f(e1, e2):
yield e1
e1_read = False
else:
yield e2
e2_read = False
except StopIteration:
return
Note that if one uses something like this instead:
[e1 if f(e1, e2) else e2 for (e1, e2) in zip(i1, i2)]
then the non-selected iterator advances every time, which is not what I want.