input: Write a function that takes a list of dictionaries and returns the list sorted by a specified attribute of the dictionaries. The function should accept two parameters: the list of dictionaries and the name of the attribute by which to sort.
  
  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([], "age") == []
  assert sort_by_attr([{"name": "Charlie", "age": 18}], "age") == [{"name": "Charlie", "age": 18}]
output: def sort_by_attr(objects, attr):
   return sorted(objects, key=lambda item: item[attr])