Let's say I have a list of numbers
numbers = ['3', '3', '4', '4']
I want to count the number of occurrences of the elements in the list, so I use collections.Counter
from collections import Counter
result = Counter(numbers)
result
Counter({'3': 2, '4': 2})
Here's something that I find quite funny, if you try to index the Counter, it will always show 0 no matter what number of index you put into it.
result[0]
Out[22]: 0
result[1]
Out[23]: 0
result[100]
Out[24]: 0
result[10000000000]
Out[26]: 0
Any idea of this interesting results?