Message221014
The introductory example already shows both ways of using a Counter:
1) How to tally one at a time:
cnt = Counter()
for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
cnt[word] += 1
2) How to count directly from a list:
words = re.findall(r'\w+', open('hamlet.txt').read().lower())
Counter(words).most_common(10) |
|
Date |
User |
Action |
Args |
2014-06-19 20:05:28 | rhettinger | set | recipients:
+ rhettinger, docs@python, BreamoreBoy, Julian.Gindi |
2014-06-19 20:05:28 | rhettinger | set | messageid: <1403208328.14.0.390682688628.issue20068@psf.upfronthosting.co.za> |
2014-06-19 20:05:28 | rhettinger | link | issue20068 messages |
2014-06-19 20:05:27 | rhettinger | create | |
|