2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by vegaseat
0

I assume you mean this example ...

# tally occurrences of words in a list
# needs Python3

import collections

cnt = collections.Counter()
for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
    cnt[word] += 1

print(cnt)

"""my result -->
Counter({'blue': 3, 'red': 2, 'green': 1})
"""
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.