input: Write a function to sort a list of objects by a specified attribute. The function should take two arguments: the list of objects and the attribute to sort by. If the attribute provided is not found in any object, the function should raise a ValueError. The sorted list should be returned in non-decreasing order.
  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": "Alice", "age": 20}, {"name": "Bob", "age": 21}], "name") == [{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}]
  assert sort_by_attr([{"name": "Alice", "age": 21}, {"name": "Bob", "age": 20}], "age") == [{"name": "Bob", "age": 20}, {"name": "Alice", "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": "Alice", "age": 20}], "age") == [{"name": "Alice", "age": 20}]
  assert sort_by_attr([], "age") == []
output: def sort_by_attr(objects, attr):
      for obj in objects:
          if attr not in obj:
              raise ValueError
      return sorted(objects, key=lambda x: x[attr])