Python編寫一個程序,中文字符頻率統計。編寫一個程序,對給定字符串中出現的全部字符(含中文字符)頻率 ##進行分析,採用降序輸出。
txt=input("請輸入一段文本:\n")
counts={}
for i in txt:
counts[i]=counts.get(i,0)+1
items=list(counts.items())
items.sort(key=lambda x:x[1],reverse=True)
for i in range(len(items)):
word,count=items[i]
print("{0:<10}{1:>5}".format(word,count))
***************************************************************