input: Write a function in Python that takes a list of objects and returns a list of those objects sorted by one of their attributes. If the list is empty, 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": 26}, {"name": "Alice", "age": 25}], "age")==[{"name": "Alice", "age": 25}, {"name": "Bob", "age": 26}]
  assert sort_by_attr([{"name": "Charlie", "age": 20}, {"name": "Alice", "age": 20}, {"name": "Bob", "age": 20}], "name")==[{"name": "Alice", "age": 20}, {"name": "Bob", "age": 20}, {"name": "Charlie", "age": 20}]
  assert sort_by_attr([], "age")==[]
  assert sort_by_attr([{"name": "Alice", "age": 30}, {"name": "Bob", "age": 30}], "name")==[{"name": "Alice", "age": 30}, {"name": "Bob", "age": 30}]
output: def sort_by_attr(objects, attr):
   return sorted(objects, key=lambda item: item[attr]) if objects else []