flatten a dictionary

🏠
 1 def flatten_dictionary(dictionary):
 2   """
 3   Time: O(n) such that n -> total number of keys in input dict
 4   Space: O(n) such that n -> total number of keys in input dict
 5   """
 6   def flatten(outk, ind):
 7     for k, v in ind.items():
 8       flat_key = "%s.%s"%(outk, k) if outk and k else (outk or k)
 9       if type(v) == dict: 
10         flatten(flat_key, v)
11       else:
12         out[flat_key] = v
13   out = {}
14   flatten('', dictionary)
15   return out