Python Program To Find Maximum frequency character in String Using Collection
01. Example
from collections import Counter string = "zeroones.org" print ("The input string : " + string) result = Counter(string) result = max(result, key = result.get) print ("The maximum frequency of a character in zeroones.org : " + str(result))
Output:
The input string : zeroones.org The maximum frequency of a character in zeroones.org : o
02. Example
import collections string = "zeroones.org" print ("The input string : " + string) result = collections.defaultdict(int) for character in string: result[character] += 1 maxValue = list(result.values()) maxKey = list(result.keys()) print("The maximum frequency of a character in zeroones.org : " + str(maxKey[maxValue.index(max(maxValue))]))
Output:
The input string : zeroones.org The maximum frequency of a character in zeroones.org : o