input: Write a function that sorts a list of dictionaries by a specified key in each dictionary. Return the sorted list. If the specified key does not exist in any dictionary, raise a KeyError.
  
  def sort_list_of_dicts_by_key(my_list, key):
      for item in my_list:
          if key not in item:
              raise KeyError(f"Key '{key}' not found in one or more dictionaries.")
      return sorted(my_list, key=lambda k: k[key])
  
  assert sort_list_of_dicts_by_key([{'name': 'Tom', 'age': 25}, {'name': 'John', 'age': 21}, {'name': 'Adam', 'age': 26}], 'age') == [{'name': 'John', 'age': 21}, {'name': 'Tom', 'age': 25}, {'name': 'Adam', 'age': 26}]
  assert sort_list_of_dicts_by_key([{'name': 'Tom', 'age': 25}, {'name': 'John', 'age': 21}, {'name': 'Adam', 'age': 26}], 'name') == [{'name': 'Adam', 'age': 26}, {'name': 'John', 'age': 21}, {'name': 'Tom', 'age': 25}]
  try:
      sort_list_of_dicts_by_key([{'name': 'Tom', 'age': 25}, {'name': 'John', 'age': 21}, {'name': 'Adam', 'age': 26}], 'height')
  except KeyError:
      assert True
  else:
      assert False
output: def sort_list_of_dicts_by_key(my_list, key):
      for item in my_list:
          if key not in item:
              raise KeyError(f"Key '{key}' not found in one or more dictionaries.")
      return sorted(my_list, key=lambda k: k[key])