input: Write a function to sort a list of dictionaries by a specified attribute. The function should take a list of dictionaries and the name of the attribute as arguments, and return the list sorted in ascending order based on the value of that attribute. If the 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": "Charlie", "age": 19}, {"name": "David", "age": 22}], "name") == [{"name": "Charlie", "age": 19}, {"name": "David", "age": 22}]
  assert sort_by_attr([], "age") == []
  assert sort_by_attr([{"name": "Eve", "height": 165}, {"name": "Frank", "height": 180}], "height") == [{"name": "Eve", "height": 165}, {"name": "Frank", "height": 180}]
output: def sort_by_attr(objects, attr):
      return sorted(objects, key=lambda item: item[attr]) if objects else []