input: Write a function to sort a list of objects by one of their attributes and return the sorted list. If the attribute does not exist for any object, the function should raise a ValueError.
  def sort_by_attr(objects, attr):
      for obj in objects:
          if attr not in obj:
              raise ValueError(f"Attribute '{attr}' not found in object: {obj}")
      return sorted(objects, key=lambda item: item.get(attr, float('inf')))
  
  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": 25}, {"name": "David", "other": 30}], "name") == [{"name": "Charlie", "age": 25}, {"name": "David", "other": 30}]
  assert sort_by_attr([{"name": "Eve", "height": 165}, {"name": "Frank", "height": 180}], "height") == [{"name": "Eve", "height": 165}, {"name": "Frank", "height": 180}]
  try:
      sort_by_attr([{"name": "Grace", "age": 22}, {"name": "Heidi"}], "age")
  except ValueError as e:
      assert str(e) == "Attribute 'age' not found in object: {'name': 'Heidi'}"
  else:
      assert False, "Expected ValueError"
output: def sort_by_attr(objects, attr):
      for obj in objects:
          if attr not in obj:
              raise ValueError(f"Attribute '{attr}' not found in object: {obj}")
      return sorted(objects, key=lambda item: item.get(attr, float('inf')))