Split a list into two parts based on a filter?

Peter Otten __peter__ at web.de
Tue Jun 11 14:18:27 EDT 2013


Joshua Landau wrote:

> 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