input: Write a function to sort a list of objects by one of their attributes. The function should take two arguments: a list of objects and a string representing the attribute name by which to sort the objects. Return the sorted list of objects.
  def sort_by_attr(objects, attr):
   return sorted(objects, key=lambda item: item[attr])
   
  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}], "name")==[{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}]
  assert sort_by_attr([{"name": "Charlie", "age": 22}, {"name": "David", "age": 19}, {"name": "Eve", "age": 20}], "age")==[{"name": "David", "age": 19}, {"name": "Eve", "age": 20}, {"name": "Charlie", "age": 22}]
  assert sort_by_attr([], "age")==[]
output: def sort_by_attr(objects, attr):
   return sorted(objects, key=lambda item: item[attr])