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


Popular posts from this blog

Phonebook - Hack the box Write up -- Web LDAP injection

wafwaf -- Hack The Box -- Web SQL injection

Cheat sheet for security+