Scala has rich api list handling, and Python as such.
You should read the itertools document. And you can find the registry key.
from itertools import ifilterfalse, ifilter, islice, tee, count def partition(pred, iterable): ''' >>> is_even = lambda i: i % 2 == 0 >>> even, no_even = partition(is_even, xrange(11)) >>> list(even) [0, 2, 4, 6, 8, 10] >>> list(no_even) [1, 3, 5, 7, 9] # Lazy evaluation >>> infi_list = count(0) >>> ingroup, outgroup = partition(is_even, infi_list) >>> list(islice(ingroup, 5)) [0, 2, 4, 6, 8] >>> list(islice(outgroup, 5)) [1, 3, 5, 7, 9] ''' t1, t2 = tee(iterable) return ifilter(pred, t1), ifilterfalse(pred, t2)
source share