code: def _get_index_for_insert(self, key, instance):
          
          if instance == 0:
              # Index method will return the first occurence of the key
              index = self.keys().index(key)
          else:
              occurrence = -1
              for index, k in enumerate(self.keys()):
                  if k == key:
                      occurrence += 1
                      if occurrence == instance:
                          # Found the key and the correct occurence of the key
                          break
  
              if occurrence != instance:
                  # Gone through the entire list of keys and the instance number
                  # given is too high for the number of occurences of the key
                  raise ValueError(
                      (
                          "Cannot insert before/after the %d "
                          "instance of the key '%s' since there are "
                          "only %d occurences of the key" % (
                              instance, key, occurrence)
                      ))
          return index
docs: Get the index of the key to insert before or after