Python: How to count the frequency of characters of a string

Simple task, i am sure that everyone can write a function to do this! but why since Python has a built in function for this? :)

>> from collections import Counter
>> test_string = "Hello! my name is Konstantinos"
>> print(Counter(test_string))
Counter({' ': 4, 'n': 4, 'o': 3, 's': 3, 'e': 2, 'l': 2, 'm': 2, 'a': 2, 'i': 2, 't': 2, 'H': 1, '!': 1, 'y': 1, 'K': 1})

Written by

DevOps engineer, loves Linux, Python, cats and Amiga computers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store