'Sorts the dictionary, so that the elements with the lowest index have
the highest counts. This reindexes the dictionary according to the
sorted frequencies, breaking ties alphabetically by token.'

def sort(self):

    sorted_pairs = sorted(self.freq.items(), key=(lambda x: ((- x[1]), x[0])))
    new_tok2ind = {}
    new_ind2tok = {}
    for (i, (tok, _)) in enumerate(sorted_pairs):
        new_tok2ind[tok] = i
        new_ind2tok[i] = tok
    self.tok2ind = new_tok2ind
    self.ind2tok = new_ind2tok
    return sorted_pairs
