input: Write a function to sort a list of objects by one of their attributes. The function should take a list of objects and the attribute name by which to sort these objects. If the input list is empty, the function should return an empty list.
  def sort_by_attr(objects, attr):
   return sorted(objects, key=lambda item: item[attr]) if objects else []
  
  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": "Bob", "age": 21}, {"name": "Alice", "age": 20}], "age")==[{'name': 'Alice', 'age': 20}, {'name': 'Bob', 'age': 21}]
  assert sort_by_attr([{"name": "Charlie", "height": 180}, {"name": "David", "height": 175}], "height")==[{'name': 'David', 'height': 175}, {'name': 'Charlie', 'height': 180}]
  assert sort_by_attr([], "age")==[]
output: def sort_by_attr(objects, attr):
   return sorted(objects, key=lambda item: item[attr]) if objects else []