You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
847 B

9 months ago
from collections import Counter
from cppy.cp_util import *
8 months ago
class TypesCheck:
9 months ago
def __init__(self, *args):
self._args = args
def __call__(self, f):
def wrapped_f(*args, **kwargs):
for i, arg_type in enumerate(self._args):
if not isinstance(args[i], arg_type):
8 months ago
raise TypeError(f" {i} expected {arg_type}, got {type(args[i])}")
9 months ago
return f(*args, **kwargs)
return wrapped_f
8 months ago
@TypesCheck(str)
9 months ago
def extract_words_(path_to_file):
return extract_file_words(path_to_file)
8 months ago
@TypesCheck(list)
9 months ago
def frequencies_(word_list):
return Counter(word_list)
8 months ago
@TypesCheck(Counter)
9 months ago
def sort_(word_freq):
return word_freq.most_common()
9 months ago
9 months ago
if __name__ == '__main__':
word_freqs = sort_(frequencies_(extract_words_( testfilepath )))
print_word_freqs(word_freqs)