There’s an itertools recipe, “partition”. On Mon, 6 Jun 2022 at 08:28, Chris Angelico <ros...@gmail.com> wrote:
> On Mon, 6 Jun 2022 at 16:42, Christopher Barker <python...@gmail.com> > wrote: > > > > I think y’all have addressed the OP’s problem — at least the performance > issues. > > > > But I think this brings up a pattern that I don’t have a nifty way to > address: > > > > How do you divide a sequence into two sequences cleanly? > > > > The filter pattern: selectively remove items from a sequence, returning > a new sequence. There are a few ways to do that in Python. > > > > But what if you need both the remaining items and the removed ones? Easy > enough to write a loop that populates two lists, but is there a nifty > one-liner? > > > > Is this a known functional pattern? > > > > I'd call that a "partitioning" task, and you're right, it's not > particularly easy in Python. > > 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/NEY4JKQMDTMS6PN3I6VK6FCICRLCG43P/ > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ 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/7TFCBUT6UD67UVYNUUTKUP26A5FGSUDO/ Code of Conduct: http://python.org/psf/codeofconduct/