As Chris Angelico notes, that's only good for finite iterables.

The recipe in the itertools docs is unbounded, but it's also unbounded in
the cache needed if you get long strings of things the do (or don't)
confirm the predicate.

On Mon, Jun 6, 2022 at 7:06 AM Stephen J. Turnbull <
[email protected]> wrote:

> Christopher Barker writes:
>
>  > How do you divide a sequence into two sequences cleanly?
>
> I don't know how to do it in a one liner, but
>
>     yes = []
>     no = []
>     for elem in seq:
>         (yes if test(elem) else no).append(elem)
>
> seems pretty clean to me.
>
> _______________________________________________
> 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/BBVBDT7KJTTOD5VQYIHBCQBU5QV32ZUB/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
_______________________________________________
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/4RIL6JUJXJDF3G6HWVU4DD33TKPEZYCI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to