input: Write a function that takes a list of objects and an attribute name as input, and returns the list of objects sorted by the specified attribute. If the attribute does not exist for any object, the function should return an empty list.
  def sort_by_attr(objects, attr):
      try:
          return sorted(objects, key=lambda item: item[attr])
      except KeyError:
          return []
  
  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": 18}], "age") == [{"name": "David", "age": 18}, {"name": "Charlie", "age": 19}]
  assert sort_by_attr([{"name": "Eve", "height": 160}, {"name": "Frank", "height": 170}], "height") == [{"name": "Eve", "height": 160}, {"name": "Frank", "height": 170}]
  assert sort_by_attr([{"name": "Grace", "age": 22}, {"name": "Heidi", "age": 23}], "grade") == []
  assert sort_by_attr([], "age") == []
output: def sort_by_attr(objects, attr):
      try:
          return sorted(objects, key=lambda item: item[attr])
      except KeyError:
          return []