Find the most occurring character and its count in Python

Share on facebook
Share on twitter
Share on pinterest

In this Python program, we will have a look at How to find the most occurring character and its count in Python programming language.

Python program to find the most occurring character and its count

from collections import Counter 
def find_most_occ_char(input): 
 wc = Counter(input) 
 s = max(wc.values()) 
 i = wc.values().index(s) 
 print wc.items()[i] 
if __name__ == "__main__": 
 input = 'codeatglance'
 find_most_occ_char(input) 

Output: (‘a’, 2)

In the above code, we have passed the characters as “codeatglance” and therefore we get the output as ‘a’ as the most occurring character in the string.

Subscribe to our Newsletter

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

Share this post with your friends

Share on facebook
Share on google
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *