input: Write a function to sort a list of objects by a specified attribute of those objects. The function should take two parameters: a list of objects and the name of the attribute by which to sort. If the list is empty, the function should return an empty 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": "Charlie", "age": 24}, {"name": "Dave", "age": 22}], "name")==[{"name": "Charlie", "age": 24}, {"name": "Dave", "age": 22}]
  assert sort_by_attr([], "age")==[]
  assert sort_by_attr([{"name": "Eve", "age": 25}], "age")==[{"name": "Eve", "age": 25}]
  assert sort_by_attr([{"name": "Frank", "age": 27}, {"name": "Grace", "age": 26}], "age")==[{"name": "Grace", "age": 26}, {"name": "Frank", "age": 27}]
output: def sort_by_attr(objects, attr):
      if not objects:
          return []
      return sorted(objects, key=lambda x: x.get(attr))