Python recursively replace character in nested dictionary?
===

I'm trying to create a generic function that replaces dots in keys of a nested dictionary. I have a non-generic function that goes 3 levels deep, but there must be a way to do this generic. Any help is appreciated! My code so far:

    output = {'key1': {'key2': 'value2', 'key3': {'key4 with a .': 'value4', 'key5 with a .': 'value5'}}} 

    def print_dict(d):
        new = {}
        for key,value in d.items():
            new[key.replace(".", "-")] = {}
            if isinstance(value, dict):
                for key2, value2 in value.items():
                    new[key][key2] = {}
                    if isinstance(value2, dict):
                        for key3, value3 in value2.items():
                            new[key][key2][key3.replace(".", "-")] = value3
                    else:
                        new[key][key2.replace(".", "-")] = value2
            else:
                new[key] = value
        return new

    print print_dict(output)