input: Write a function in Python that takes a list of dictionaries and a string representing an attribute name, and returns the list sorted by that attribute. The function should be called `sort_by_attr`.
  
  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}]
output: def sort_by_attr(objects, attr):
   return sorted(objects, key=lambda item: item[attr])