Solving the Review Section of Python:Classes Lesson

I browsed through python documentation at the following link: , 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):
  def append(self, value):
list_object = SortedList([5, 2, 80])

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"})

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:

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.