Split a list into two parts based on a filter?

Joshua Landau joshua.landau.ws at gmail.com
Tue Jun 11 10:22:56 EDT 2013


On 11 June 2013 01:11, Peter Otten <__peter__ at web.de> wrote:
> def partition(items, predicate=bool):
>     a, b = itertools.tee((predicate(item), item) for item in items)
>     return ((item for pred, item in a if not pred),
>             (item for pred, item in b if pred))

I have to tell you this is the coolest thing I've read today. I'd
never have thought of that.



More information about the Python-list mailing list