On Tue, 7 Jun 2022 at 10:26, Steven D'Aprano <st...@pearwood.info> wrote:
>
> Why don't you use the version from the itertools recipes?
>
>
> ```
> from itertools import tee, filterfalse
> def partition(pred, iterable):
>     "Use a predicate to partition entries into false entries and true entries"
>     # partition(is_odd, range(10)) --> 0 2 4 6 8   and  1 3 5 7 9
>     t1, t2 = tee(iterable)
>     return filterfalse(pred, t1), filter(pred, t2)
> ```
>
>

Calls the predicate twice for every element, so it's only good for a
guaranteed-deterministic predicate. You may want to read the thread
before responding.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/NS6ORDJ4STDGOJID5B5NQXZ4MVC5QORQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to