from collections import deque
def partition(pred, iterable):
results = deque([]), deque([])
def gen_split(only):
for thing in iterable:
if results[only]:
yield results[only].popleft()
results[not pred(thing)].append(thing)
for thing in results[only]:
yield thing
return gen_split(True), gen_split(False)
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/EUAYPXMZM4DOGTAAUURNOMWTDU65K6UY/
Code of Conduct: http://python.org/psf/codeofconduct/