input: Write a function to take a list of objects and return a new list with these objects sorted by one of their attributes. If the input list is empty, return an empty list. The function should accept two arguments: the first is the list of objects, and the second is the name of the attribute to sort by.
  
  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": 18}, {"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}], "name") == [{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}, {"name": "Charlie", "age": 18}]
  assert sort_by_attr([], "age") == []
  assert sort_by_attr([{"name": "Alice", "age": 20}], "age") == [{"name": "Alice", "age": 20}]
output: def sort_by_attr(objects, attr):
      return sorted(objects, key=lambda x: x.get(attr))