Map a function f:{primitive} -> B to a dictionary.

def dict_map(f, primitive, dic):
    """Map a function f:{primitive} -> B to a dictionary."""

    if primitive(dic):
        return f(dic)
    if isinstance(dic, Mapping):
        return {dict_map(f, primitive, key): dict_map(f, primitive, value)
                for key, value in dic.items()}
    if isinstance(dic, str):
        return dic
    if isinstance(dic, Sequence):
        return [dict_map(f, primitive, value) for value in dic]
    return dic