January 27, 2023

Python's Counter

The problem Python has a Counter object – it’s found in the collections module – and I’ve become convinced that it’s… a bit weird? The basic idea is fine: it’s a dictionary but the keys are things you want to count, and the values are the amount of the thing you have counted. The neat thing is if you initialise a counter with an iterable like a string or a list, it’ll give you the counts for the number of times each element appears. Read more

© Seamus Bradley 2021–3

Powered by Hugo & Kiss.