input: Write a python function to flatten a nested dictionary.
  assert flatten({"a": 1, "b": {"c": 2, "d": 3}}) == {"a": 1, "b.c": 2, "b.d": 3}
  assert flatten({"a": {"b": {"c": {"d": 1}}}}) == {"a.b.c.d": 1}
  assert flatten({"x": {"y": {"z": 3}}, "a": 4}) == {"x.y.z": 3, "a": 4}
output: def flatten(d, parent_key='', sep='.'):
      items = []
      for k, v in d.items():
          new_key = f"{parent_key}{sep}{k}" if parent_key else k
          if isinstance(v, dict):
              items.extend(flatten(v, new_key, sep=sep).items())
          else:
              items.append((new_key, v))
      return dict(items)