def renamed_prefix(cfg, old, new):
    """
    Returns a new dictionary that has all keys of `cfg` that begin with `old`
    renamed to begin with `new` instead.
    """
    renamed = dict(cfg)
    for k in cfg.keys():
        if k.startswith(old):
            renamed[new + k[len(old):]] = renamed.pop(k)
    return renamed