>>> c = Counter() # 建立一個空的Counter類 >>> c = Counter('gallahad') # 從一個可iterable對象(list、tuple、dict、字符串等)建立 >>> c = Counter({'a': 4, 'b': 2}) # 從一個字典對象建立 >>> c = Counter(a=4, b=2) # 從一組鍵值對建立
>>> c = Counter("abcdefgab") >>> c["a"] 2 >>> c["c"] 1 >>> c["h"] 0
>>> c = Counter('abracadabra') >>> c.most_common() [('a', 5), ('r', 2), ('b', 2), ('c', 1), ('d', 1)] >>> c.most_common(3) [('a', 5), ('r', 2), ('b', 2)]
[參考詳細連接——Python標準庫——collections模塊的Counter類](http://www.pythoner.com/205.html)html