If I have a function which has to be executed for the nested dictionaries inside a dictionary. Then how should I execute it ?

For example:

```
# I have the below dictionary
d = {'a':1, 'b':2, 'c':3, 'd': {'e':4, 'f':5}}

# I wanted a result as below
{'a': 1, 'b': 2, 'c': 3, 'e': 4, 'f': 5}

#I have executed it by 

for i, j in d.items():

    if type(j) == dict:
        for key,value in d[i].items():
            d[key] = value
        d.pop(i, None)

print d

#output
{'a': 1, 'c': 3, 'b': 2, 'e': 4, 'f': 5}

```

But what if there are many nested dictionaries? I am kind of confused on this ? Any suggestions?

Thanks in advance.