Joined February 2012
·

Paul Eipper

nKey
·
Brasil
·
·

Posted to Efficient sifting iterator for Python over 1 year ago

Y U NO partition ?!

def partition(pred, iterable):
    'Use a predicate to partition entries into false entries and true entries'
    # partition(is_odd, range(10)) --> 0 2 4 6 8   and  1 3 5 7 9
    t1, t2 = tee(iterable)
    return filterfalse(pred, t1), filter(pred, t2)

http://docs.python.org/dev/library/itertools.html#itertools-recipes

Achievements
78 Karma
1,982 Total ProTip Views