思路:暂存当前最大词(为比较字符串大小)及其频率(为比较频率)
先比较频率,仅当频率相同时比较字符串大小
#coding:utf-8
#printice 3 data cleaning and frequency statistics
'''
输出长度大于2且最多的单词。
如果存在多个单词出现频率一致,
请输出按照Unicode排序后最大的单词。
'''
import jieba
story=open("C:/Users/UMR/Desktop/沉默.txt","rt")
txt=story.read()
story.close()
words=jieba.lcut(txt)#segment the words
count=dict()
for word in words:
if len(word)<2:
continue
else:
count[word]=count.get(word,0)+1
#请输出按照Unicode排序后最大的单词。
#思路:暂存当前最大词(为比较字符串大小)及其频率(为比较频率)
#先比较频率,仅当频率相同时比较字符串大小
nowmax=0 #当前最大频率单词的频率(int)
max='' #当前最大频率的单词(string)
for wd in count:
#频率大的情况
if count[wd]>nowmax:
nowmax=count[wd]
max=wd
#频率相等的情况-->仅当 新词 大于 旧词时才替换
if count[wd]==nowmax and wd>max:
max=wd
print(max)
#practice 2 reverse the dictionary
try:
inp=eval(input())
print(type