code: def weighted_choices(self, word, exclude=None, flatten=False):
          
          exclude = exclude if exclude is not None else set()
          weighted_choices = defaultdict(int)
          total_sum = 1
          for start in range(len(word) - 1, -1, -1):
              current_sum = 0
              sub_word = word[start:]
              if sub_word in self:
                  for successor, weight in self[sub_word].items():
                      if successor not in exclude:
                          weight = 1 if flatten else weight
                          weight = weight * total_sum
                          weighted_choices[successor] += weight
                          current_sum += weight
              total_sum += current_sum
          return weighted_choices
docs: Return the weighted choices for word from this table.
          
          :param word: the word (as a string);
          :param exclude: if not None, a set of characters to exclude from the
                          weighted choices;
          :param flatten: whether or not consider this table as flattened;
          :return: the weighted choices for word from this table.
          
          The weighted choices are computed such that:
          * for a given suffix of word, the possible choices are the ones defined
            by table;
          * the weights of these possible choices are either 1 if flatten is
            True, or the weights defined by table otherwise;
          * the weights are accumulated for each suffix, but longer suffixes have
            scaled up weights to assure that all shorter suffixes will have less
            probabilities to be picked.