Question:
A function that prints a dictionary as in the example below
recursive_dict = {
   'a': 1,
   'b': {
       'c': 1,
       'd': 4
   },
   'e':
   {
       'f': 3,
       'g':
       {
           'h': 5,
           'i': 6
       }
   },
   'j': 10
}
to
'a' - 1
'b' - 'c' - 1
'b' - 'd' - 4
'e' - 'f' - 3
'e' - 'g' - 'h' - 5
'e' - 'g' - 'i' - 6
'j' - 10
My Code:
Any criticism about the code is welcomed as i am a python beginner, or any way to make this easier to read. The code doesn't work after a higher level recurssion value as it keeps the old key. I think i have to detect when a dictionary is ending so i remove from the old_key the last key i concatenated. Another harder? idea is to convert the dictionary to a tree and then proceed to read all the branches of the tree.
def print_dictionary_tree(tree_dict, default_separator='-', branch="", old_key=""):
    for key, value in tree_dict.items():
        if type(value) != dict:
            if old_key == "":
                branch += f"%{key}% {default_separator} {value} \n"
            else:
                branch += f"{old_key} {default_separator} /{key}/ {default_separator} {value} \n"
        else:
            if old_key != "":
                old_key += f" {default_separator} %{key}%"
            elif key != value.get(key):
                old_key += f"^{key}^"
            branch += print_dictionary_tree(value, default_separator, "", old_key)
    return branch
Returns
'a' - 1 
'b' - 'c' - 1 
'b' - 'd' - 4 
'b' - 'e' - 'f' - 3 
'b' - 'e' - 'g' - 'h' - 5 
'b' - 'e' - 'g' - 'i' - 6 
'b' - 'e' - 'j' - 10 
 
     
    