当前位置: 首页 > 工具软件 > Walden > 使用案例 >

walden

卫嘉谊
2023-12-01

英文文本中单词统计


f = open(r’C:\Users\Administrator\Desktop\Walden.txt’,‘r’)
lines=f.readlines()
a = []
for line in lines:
tmp_list = line.split(" “)
for word in tmp_list:
a.append(word.replace(’,’,’’).replace(’.’,’’).replace(’”’,’’).replace(’-’,’’))
a

dict = {}
word_set = set(a)
for word in word_set:
count_num = a.count(word)
dict[word] = count_num
dict
sorted(dict.items(),key=lambda item:item[1],reverse = True)

 类似资料:

相关阅读

相关文章

相关问答