input: Write a function to sort a list of objects by one of their attributes in ascending order. The function should return the sorted list based on the specified attribute. If the attribute does not exist in any of the objects, the function should handle the exception and return the original list.
  assert sort_by_attr([{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}], "age")==[{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}]
  assert sort_by_attr([{"name": "Alice", "age": 21}, {"name": "Bob", "age": 20}], "age")==[{"name": "Bob", "age": 20}, {"name": "Alice", "age": 21}]
  assert sort_by_attr([{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}], "name")==[{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}]
  assert sort_by_attr([{"name": "Alice", "age": 21}, {"name": "Bob", "age": 20}], "name")==[{"name": "Alice", "age": 21}, {"name": "Bob", "age": 20}]
  assert sort_by_attr([], "name")==[]
output: def sort_by_attr(lst, attr):
      try:
          return sorted(lst, key=lambda x: x[attr])
      except KeyError:
          return lst