dev
zj3D 9 months ago
parent 44c1f9eb1e
commit 18f3901592

@ -17,14 +17,12 @@ def frequencies(word_list):
def sort(word_freq): def sort(word_freq):
return sorted( word_freq.items(), key=lambda x: x[1], reverse=True ) return sorted( word_freq.items(), key=lambda x: x[1], reverse=True )
def printall(word_freqs, n = 10 ):
for word, freq in word_freqs[ :n ]:
print(word, '-', freq)
if __name__ == "__main__": if __name__ == "__main__":
txtcontent = read_file( testfilepath ) txtcontent = read_file( testfilepath )
word_list = extractwords( txtcontent ) word_list = extractwords( txtcontent )
word_freqs = frequencies( word_list ) word_freqs = frequencies( word_list )
word_sort = sort ( word_freqs ) word_sorts = sort ( word_freqs )
printall(word_sort)
for tf in word_sorts[:10]:
print(tf[0], '-', tf[1])

@ -3,7 +3,7 @@ import aiofiles
from collections import Counter from collections import Counter
from cppy.cp_util import * from cppy.cp_util import *
########## 不太合适的一个场景 ######################
# #
# 协程 # 协程
# #
@ -25,7 +25,7 @@ async def main():
top_words = await count_words(text) top_words = await count_words(text)
wordfreqs += top_words wordfreqs += top_words
for word, count in wordfreqs.most_common(10): for word, count in wordfreqs.most_common(10):
print(f"{word}: {count//10}") print(f"{word}: {count//10}") # 突出 Io 的提升价值
# 运行异步主函数 # 运行异步主函数

@ -1,6 +1,8 @@
import threading, queue import threading, queue
from cppy.cp_util import * from cppy.cp_util import *
# 能否简单的共享全局变量
# 处理单词 # 处理单词
def process_words(word_space, freq_space, stopwords): def process_words(word_space, freq_space, stopwords):
word_freqs = {} word_freqs = {}
Loading…
Cancel
Save