Added limit to minimum frequency = 10 + Ordered by frequency

This commit is contained in:
Luka 2020-08-21 15:05:30 +02:00
parent edea80e6e0
commit e38ff4c7b0

View File

@ -174,6 +174,12 @@ def main(args):
write_file_path = os.path.join(args.output, file_name) write_file_path = os.path.join(args.output, file_name)
with open(read_file_path, 'r') as rf, open(write_file_path, 'w') as wf: with open(read_file_path, 'r') as rf, open(write_file_path, 'w') as wf:
original_text, stats = get_new_stats(rf) original_text, stats = get_new_stats(rf)
freq_pos = original_text[0].index('Frequency')
original_text = [original_text[0]] + [l for l in original_text[1:] if int(l[freq_pos]) >= 10]
if len(original_text) > 1:
original_text = [original_text[0]] + sorted(original_text[1:], key=lambda x: -1 * int(x[freq_pos]))
else:
original_text = [original_text[0]]
write_new_stats(wf, original_text, stats, file_name, word_order) write_new_stats(wf, original_text, stats, file_name, word_order)
if __name__ == '__main__': if __name__ == '__main__':