input: Write a function in Python that takes a list of objects and returns a list of those objects sorted by one of their attributes. The function should accept two parameters: the list of objects and the name of the attribute to sort by.
  
  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])