'Save dictionary to file.
Format is \'token<TAB>count\' for every token in the dictionary, sorted
by count with the most frequent words first.
If ``append`` (default ``False``) is set to ``True``, appends instead of
overwriting.
If ``sort`` (default ``True``), then first sort the dictionary before saving.'

def save(self, filename=None, append=False, sort=True):

    filename = (self.opt['model_file'] if (filename is None) else filename)
    print 'Dictionary:    saving    dictionary    to    {}'.format(filename)
    if sort:
        self.sort()
    with open(filename, ('a' if append else 'w')) as write:
        for i in range(len(self.ind2tok)):
            tok = self.ind2tok[i]
            cnt = self.freq[tok]
            write.write('{tok} DCTB {cnt}\n'.format(tok=escape(tok), cnt=cnt))
