input: Write a function to sort a list of objects by one of their attributes. The function should take two arguments: the list of objects and the attribute name by which the objects should be sorted. If the attribute name is not found in any object, it should raise a ValueError.
  sort_by_attr([{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}], "age") == [{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}]
  sort_by_attr([{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}], "name") == [{"name": "Alice", "age": 20}, {"name": "Bob", "age": 21}]
  sort_by_attr([{"name": "Charlie", "age": 19}, {"name": "Bob", "age": 21}], "name") == [{"name": "Bob", "age": 21}, {"name": "Charlie", "age": 19}]
  assert sort_by_attr([{"name": "David", "age": 30}, {"name": "Eve", "age": 28}], "invalid_attr") # ValueError should be raised
  assert sort_by_attr([], "age") == []
output: def sort_by_attr(objects, attr):
      for obj in objects:
          if attr not in obj:
              raise ValueError("Attribute not found in object")
      return sorted(objects, key=lambda x: x[attr])