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. If the attribute is not found in any of the objects, return an empty list.
  def sort_by_attr(objects, attr):
   for obj in objects:
      if attr not in obj:
          return []
   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}]
  assert sort_by_attr([{"name": "Charlie", "age": 19}, {"name": "David", "age": 22}], "age") == [{"name": "Charlie", "age": 19}, {"name": "David", "age": 22}]
  assert sort_by_attr([{"name": "Eve", "age": 24}, {"name": "Frank", "age": 23}], "height") == []
output: def sort_by_attr(objects, attr):
      for obj in objects:
          if attr not in obj:
              return []
      return sorted(objects, key=lambda item: item[attr])