flatten a dictionary

🏠
 1def flatten_dictionary(dictionary):
 2  def flat(outk, ind):
 3    for k, v in ind.items():
 4      if type(v) == dict: 
 5        flat("%s.%s"%(outk, k) if outk and k else (outk or k), v)
 6      else:
 7        out[flat_key] = v
 8  out = {}
 9  flat('', dictionary)
10  return out

Time and Space Complexity