Collections-Counter

Sat 17 May 2025

title: "Collections Counter" author: "Rj" date: 2019-04-20 description: "List Test" type: technical_note draft: false


from collections import Counter
cnt = Counter()

for word in ['Toronto', 'Montreal', 'Montreal', 'Waterloo', 'Toronto', 'Toronto']:
    cnt[word] += 1
cnt
Counter({'Montreal': 2, 'Toronto': 3, 'Waterloo': 1})
type(cnt)
collections.Counter


Score: 5

Category: basics