# sort the dictionary and get the top n top_n = sorted(val_frequencies.items(), key=lambda x: x[1], reverse=True)[:n] top_n_str = "" for entry in top_n: top_n_str = top_n_str + entry[0] + " : " + str(entry[1]) + " time(s)" + "\n" table.add_row([key,freq_count,top_n_str]) to_write.write(key) to_write.write("\n") to_write.write(sent_str) to_write.write("\n") to_write.close() print("TOTAL NOUN PHRASES FOUND = ", total_count) print("") print("FILE CREATED CALLED all_occurences.txt CONTAINING SEQUENCE TYPES AND ALL UNIQUE OCCURENCES.") print("") print("Note that DT=determiner, Adj=adjective, and Noun=noun(of course)") table.align = "l" print(table.draw())