Solving the Review Section of Python:Classes Lesson

I browsed through python documentation at the following link: https://docs.python.org/2/library/stdtypes.html?highlight=dict#mapping-types-dict , and learned that there is a built-in missing method that basically give the user the option to return anything if a value is missing from a dictionary. The following code is the result of implementing that method:

class SortedList(list):
  def __init__(self,the_list):
    super().__init__(the_list)
    self.sort()
  def append(self, value):
    super().append(value)
    self.sort()
    
list_object = SortedList([5, 2, 80])
print(list_object)

class BetterDict(dict):
  def __iter__(self, user_dict, key):
    super().__iter__(user_dict, key)
  
  def __missing__(self, key):
    return False
    
dictionary_object = BetterDict({"hello!": "polite"})
print(dictionary_object[55])

However, I’m curious if there is another way to solve the last part of the last question (i.e. having a user_defined output if a key is missing in a dictionary).

Review Section of Python:Classes

P.S. the methods in bold are actually dunder methods.

looking at the python3 documentation:

https://docs.python.org/3/reference/datamodel.html#object.missing

the missing magic method is what gets called when a key does not exist, thus if you want to change this behavior, this seems like the right method to overwrite.