input: Write a function to sort an array of strings by their lengths in ascending order. If the given array is empty, return the empty array.
  assert sort_by_length(["cat", "dog", "apple", "banana"])==["cat", "dog", "apple", "banana"]
  assert sort_by_length(["python", "java", "c"])==["c", "java", "python"]
  assert sort_by_length(["apple"])==["apple"]
  assert sort_by_length([])==[]
  assert sort_by_length(["short", "verylongword", "medium"])==["short", "medium", "verylongword"]
output: def sort_by_length(arr):
      return sorted(arr, key=len)