def PrintWordStats(word_stats_out):
    try:
        f = open(word_stats_out, 'w')
    except:
        sys.exit('segment_ctm_edits.py: error opening word-stats file --word-stats-out={0} for writing'.format(word_stats_out))
    global word_count_pair
    for (key, pair) in sorted(word_count_pair.items(), key=(lambda item: (((item[1][1] ** 3) * 1.0) / (item[1][0] ** 2))), reverse=True):
        badness = ((pair[1] * 1.0) / pair[0])
        total_count = pair[0]
        print(key, badness, total_count, file=f)
    try:
        f.close()
    except:
        sys.exit('segment_ctm_edits.py: error closing file --word-stats-out={0} (full disk?)'.format(word_stats_out))
    print('segment_ctm_edits.py: please see the file {0} for word-level statistics saying how frequently each word was excluded for a segment; format is <word> <proportion-of-time-excluded> <total-count>.  Particularly problematic words appear near the top of the file.'.format(word_stats_out), file=sys.stderr)
def PrintWordStats(word_stats_out):
    try:
        f = open(word_stats_out, 'w')
    except:
        sys.exit('segment_ctm_edits.py: error opening word-stats file --word-stats-out={0} for writing'.format(word_stats_out))
    global word_count_pair
    for (key, pair) in sorted(word_count_pair.items(), key=(lambda item: (((item[1][1] ** 3) * 1.0) / (item[1][0] ** 2))), reverse=True):
        badness = ((pair[1] * 1.0) / pair[0])
        total_count = pair[0]
        print(key, badness, total_count, file=f)
    try:
        f.close()
    except:
        sys.exit('segment_ctm_edits.py: error closing file --word-stats-out={0} (full disk?)'.format(word_stats_out))
    print('segment_ctm_edits.py: please see the file {0} for word-level statistics saying how frequently each word was excluded for a segment; format is <word> <proportion-of-time-excluded> <total-count>.  Particularly problematic words appear near the top of the file.'.format(word_stats_out), file=sys.stderr)