我使用Python集合庫打印出字符串中最常見的字符以及它重複的次數。使用Python修改collections.Counter的輸出
import collections
results = collections.Counter("this is fun")
listresults= results.most_common()
print listresults
這是我的結果是什麼:
[(' ', 2), ('i', 2), ('s', 2), ('f', 1), ('h', 1), ('n', 1), ('u', 1), ('t', 1)]
這不是我想要的。我想要類似
[(2,"i") (2, " "),...]
沒有人知道如何產生所需的結果嗎?
你沒有得到這樣的輸出' Counter(「這很有趣」),是嗎? – Volatility 2013-04-27 01:43:53
對不起,結果來自其他東西 – 2013-04-27 01:45:45