The task is to find the frequent occurred character in the given string with it occurrence number.
from collections import Counter def find(ip_char): count = Counter(ip_char) # Most occured char max_occur = max(count.values()) index = count.values().index(max_occur) print(count.items()[index]) ip_char = 'alphabet' find(ip_char)
In the above python code, we have transformed the given string into a dictionary using COUNTER() function. The COUNTER() function stores the data as key-value pair where keys are the characters and values as its number of occurrence. We extract the maximum occurred value and its index and print the output.