Counter in python
Counter class is a special type of object data-set provided with the collections module in Python3. It collects how many elements it have in a string or a dictionary or a list.
from collections import Counter
S = "aab"
a = Counter(S)
method of Counter:
- elements()
for i in a.elements():
print(i)
we get aab(return to all the elements)
- get('a')
- most_common(1)
- keys()
- values()
- update('aabb') add the elements in the counter
- subtrct('aa') make the subtract with the original counter