我現在有的代碼:如何將一個Counter對象轉換爲一個可用的對列表?
from collections import Counter
c=Counter(list_of_values)
回報:
Counter({'5': 5, '2': 4, '1': 2, '3': 2})
我想通過項目,不出現的次數進行排序這個列表爲數字(/字母)順序。我怎麼能轉換到這一點對,如清單:
[['5',5],['2',4],['1',2],['3',2]]
注:如果我使用c.items(),我得到:dict_items([( '1',2),( '3', 2),('2',4),('5',5)]) 這不會幫助我...
在此先感謝!
那如何幫不了你?你不能簡單地排序'c.items()'的結果嗎? – kindall