input: Write a python function to sort dictionary keys by their lengths.
  assert sort_by_length({'aaa': 1, 'b': 2, 'cc': 3}) == {'b': 2, 'cc': 3, 'aaa': 1}
  assert sort_by_length({'apple': 5, 'dog': 1, 'elephant': 3}) == {'dog': 1, 'apple': 5, 'elephant': 3}
  assert sort_by_length({'x': 10, 'y': 20, 'long_key': 30}) == {'x': 10, 'y': 20, 'long_key': 30}
output: def sort_by_length(d):
      return dict(sorted(d.items(), key=lambda x: len(x[0])))