from itertools import groupby from operator import itemgetter inputs = ((x > 5, x) for x in range(10)) (_, a), (_, b) = groupby(inputs, key=itemgetter(0)) print(list(a)) print(list(b))