For example, splitting list by even and odd
arr = range(20)even, odd = reduce(lambda res, next: res[next % 2].append(next) or res, arr, ([], []))
Or in general:
def split(predicate, iterable): return reduce(lambda res, e: res[predicate(e)].append(e) or res, iterable, ([], []))
Advantages:
- Shortest posible way
- Predicate applies only once for each element
Disadvantages
- Requires knowledge of functional programing paradigm