any modules having a function to partition a list by predicate provided?
knifenomad at gmail.com
Tue Apr 20 03:00:39 CEST 2010
i know it's not very hard to get that solution.
just by implementing simple function like below.
def partition(target, predicate):
split a list into two partitions with a predicate
any better ideas? :)
true = 
for item in target:
return true, false
but i wonder if there's another way to do this with standard libraries
or .. built-ins.
if it's not, i'd like the list objects to have partition method like
string module has.
true, false = [1,2,3,4].partition(lambda x: x >1)
print true, false
More information about the Python-list