2011-12-01から1日間の記事一覧
だいぶ前に defaultdict について書いたけど、出現回数のカウントは collections.Counter クラスの方がシンプルに書ける。 # Python 3.2.2 from collections import Counter c = Counter('abrakadabra') for k, v in c.items(): print(k, '----', v) # 結果:…
だいぶ前に defaultdict について書いたけど、出現回数のカウントは collections.Counter クラスの方がシンプルに書ける。 # Python 3.2.2 from collections import Counter c = Counter('abrakadabra') for k, v in c.items(): print(k, '----', v) # 結果:…