import functools


def partition_dict(d, pred, dict_class=dict):
    """
    Split a dict in two based on a predicate. ``d`` is a dict (or dict-like)
    object. ``pred(key, value)`` is a function that returns a bool, which will
    determine which dict the key, value pair will be sent to. Returns two
    dicts, ``(false, true)``, where ``false`` is a dict with all pairs where
    ``pred`` returned ``False``, and ``true`` is a dict with all pairs where
    ``pred`` returned ``True``.
    """
    def iterator(acc, pair):
        f, t = acc
        key, val = pair
        if pred(key, val):
            t[key] = val
        else:
            f[key] = val
        return f, t
    return functools.reduce(iterator, d.items(), (dict_class(), dict_class()))