def write_words_txt(orig_lines, highest_numbered_symbol, nonterminals, filename):
    "Writes updated words.txt to 'filename'.  'orig_lines' is the original lines\n       in the words.txt file as a list of strings (without the newlines);\n       highest_numbered_symbol is the highest numbered symbol in the original\n       words.txt; nonterminals is a list of strings like '#nonterm:foo'."
    with open(filename, 'w', encoding='latin-1') as f:
        for l in orig_lines:
            print(l, file=f)
        cur_symbol = (highest_numbered_symbol + 1)
        for n in (['#nonterm_begin', '#nonterm_end'] + nonterminals):
            print('{0} {1}'.format(n, cur_symbol), file=f)
            cur_symbol = (cur_symbol + 1)
Writes updated words.txt to 'filename'.  'orig_lines' is the original lines
in the words.txt file as a list of strings (without the newlines);
highest_numbered_symbol is the highest numbered symbol in the original
words.txt; nonterminals is a list of strings like '#nonterm:foo'.
def write_words_txt(orig_lines, highest_numbered_symbol, nonterminals, filename):
    "Writes updated words.txt to 'filename'.  'orig_lines' is the original lines\n       in the words.txt file as a list of strings (without the newlines);\n       highest_numbered_symbol is the highest numbered symbol in the original\n       words.txt; nonterminals is a list of strings like '#nonterm:foo'."
    with open(filename, 'w', encoding='latin-1') as f:
        for l in orig_lines:
            print(l, file=f)
        cur_symbol = (highest_numbered_symbol + 1)
        for n in (['#nonterm_begin', '#nonterm_end'] + nonterminals):
            print('{0} {1}'.format(n, cur_symbol), file=f)
            cur_symbol = (cur_symbol + 1)