Skip to content

Instantly share code, notes, and snippets.

@muammar
Created August 1, 2019 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muammar/d6030a68ac6bfd4022b7dc2cad4bab7a to your computer and use it in GitHub Desktop.
Save muammar/d6030a68ac6bfd4022b7dc2cad4bab7a to your computer and use it in GitHub Desktop.
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