def recursive_map(f, d):
    """Map f over d, including stepping into any nested dictionaries."""
    out = {}
    for k, v in d.items():
        if isinstance(v, dict):
            out[k] = recursive_map(f, v)
        else:
            out[k] = f(k, v)
    return out