Python·100 questions

How to use collections.Counter and defaultdict?

Answer
Counter counts frequencies: Counter(words).
most_common(n) — top-N.
defaultdict(list) is convenient for grouping.
defaultdict(int) — counter without if.
Improves readability and speed of code.
Was this answer helpful?

More questions in this topic

Related questions from other topics