Created
August 1, 2019 21:12
-
-
Save muammar/d6030a68ac6bfd4022b7dc2cad4bab7a to your computer and use it in GitHub Desktop.
Counting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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