input: Write a function to sort a list of objects based on one of their attributes and return the sorted list. The function should take two arguments: a list of objects and the attribute name by which to sort the objects. If the attribute name is not found in any object, the function should raise a ValueError.
  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": "Charlie", "age": 19}, {"name": "David", "age": 22}], "name") == [{"name": "Charlie", "age": 19}, {"name": "David", "age": 22}]
  assert sort_by_attr([], "age") == []
  assert sort_by_attr([{"name": "Eve", "age": 25}], "age") == [{"name": "Eve", "age": 25}]
  try:
      sort_by_attr([{"name": "Frank", "age": 26}], "height")
  except ValueError:
      assert True
  except:
      assert False
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])