def partition(it, pred):
    buf = [[], []]
it = iter(it)

def get(t):
    while True:
        while buf[t]:
            yield buf[t].pop(0)
x = next(it)
if t == bool(pred(x)):
    yield x
else:
    buf[not t].append(x)
return get(True), get(False)
Python-эквивалент раздела scala