f=open("2.txt",'r')
ll=f.read()
'''將空格都取代為逗號,方便后面的split()'''
ll=ll.replace(" ",',')
'''防止由於文檔編輯不規范出現雙逗號的情況'''
ll=ll.replace(",,",',')
l=ll.split("\n")
rows=[]
dic={}
for i in l:
row=i.split(",")
rows.append(row)
for ii in rows:
for each in ii:
if each in dic:
dic[each]=dic[each]+1
else:
dic[each]=1
#輸出所有的排序:
print(sorted(dic.items(),key=lambda x:x[1],reverse=True))
'''只輸出最大的值'''
HighValue=0
HighKey=None
for each in dic:
if dic[each]>HighValue:
HighValue=dic[each]
HighKey=each
print(HighKey,HighValue)