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.
24 lines
657 B
24 lines
657 B
9 months ago
|
from cppy.cp_util import *
|
||
|
|
||
8 months ago
|
# 这个例子没有实际意义,是用来帮助理解下一个例子
|
||
|
# 程序,只需要做第一件事情,后面的顺序逻辑写到各个函数里面了
|
||
|
|
||
8 months ago
|
def readfile(path_to_file, func):
|
||
|
data = read_file(path_to_file)
|
||
|
func(data, frequencies)
|
||
|
|
||
|
def extractwords(str_data,func):
|
||
|
func(extract_str_words(str_data), sort)
|
||
9 months ago
|
|
||
|
def frequencies(word_list, func):
|
||
|
wf = get_frequencies(word_list)
|
||
8 months ago
|
func(wf, printall)
|
||
9 months ago
|
|
||
|
def sort(wf, func):
|
||
8 months ago
|
func(sort_dict(wf), None)
|
||
9 months ago
|
|
||
8 months ago
|
def printall(word_freqs, func):
|
||
|
print_word_freqs(word_freqs)
|
||
9 months ago
|
|
||
|
if __name__ == "__main__":
|
||
8 months ago
|
readfile(testfilepath, extractwords)
|