input: Write a function to sort an array of strings by their length. The function should return the sorted array with the shortest string at the beginning and the longest string at the end. If the given array is empty, it should return an empty array.
  def sort_by_length(strings):
      for i in range(len(strings) - 1):
          for j in range(i + 1, len(strings)):
              if len(strings[i]) > len(strings[j]):
                  strings[i], strings[j] = strings[j], strings[i]
      return strings
  assert sort_by_length(["cat", "dog", "apple", "banana"])==["cat", "dog", "apple", "banana"]
  assert sort_by_length(["banana", "apple", "dog", "cat"])==["cat", "dog", "apple", "banana"]
  assert sort_by_length(["a", "bb", "ccc", "dddd"])==["a", "bb", "ccc", "dddd"]
  assert sort_by_length(["elephant", "mouse", "ant", "giraffe"])==["ant", "mouse", "giraffe", "elephant"]
  assert sort_by_length([])==[]
output: def sort_by_length(strings):
      return sorted(strings, key=len)