Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Counting
In [1]: stuff = ["a", "a", "c", "b", "b", "b"]
In [2]: counter = {}
In [3]: for element in stuff:
...: if element not in counter.keys():
...: counter[element] = 0
...: counter[element] += 1
...:
In [4]: counter
Out[4]: {'a': 2, 'c': 1, 'b': 3}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.