Words frequency
Please check my script and tell me, how would you simplify or improve it? This script calculates 10 (or as many as you want) most often words found in the format file `.txt.` To start the script, type in the console: python lang_frequency.py --name script_name.txt The result of the code execution will be similar: [('и', 1728), ('в', 1576), ('не', 1360), ('он', 1190), ('что', 1100), ('я', 1066), ('на', 1000), ('его', 690), ('это', 688), ('с', 663)] To use your `.txt` format file, you need to put it in the folder with the script from collections import Counter import re import sys import argparse def create_parser (): parser = argparse.ArgumentParser() parser.add_argument ('-n', '--name', type=argparse.FileType()) return parser parser = create_parser() namespace = parser.parse_args(sys.argv[1:]) text = namespace.name.read() number = int(input("Type a number of most often words you want to know ")) words = re.findall(r'\w+', text.lower()) ten_most_frequent_words = Counter(words).most_common(number) print(ten_most_frequent_words)