• Register
468 points
9 3 2
# This Python 3 code for 
# getting the maximum frequency 
# of character in string
  
# string initialization
input_str = "GreekforGreek"
  
# printing out the original string
print ("Original string is : " + input_str)
  
# naive method 
# getting the maximum frequency 
tot_freq = {}
for i in input_str:
    if i in tot_freq:
        tot_freq[i] += 1
    else:
        tot_freq[i] = 1
res = max(tot_freq, key = tot_freq.get) 
  
# printing out result 
print (" highest frequency character is : " + str(res))

 

Example 2

# This Python 3 code for 
# getting the maximum frequency 
# of character in string
  
# string initialization
input_str = "wholetthedogsout"
  
# printing out the original string
print ("Original string is : " + input_str)
  
# naive method 
# getting the maximum frequency 
tot_freq = {}
for i in input_str:
    if i in tot_freq:
        tot_freq[i] += 1
    else:
        tot_freq[i] = 1
res = max(tot_freq, key = tot_freq.get) 
  
# printing out result 
print (" highest frequency character is : " + str(res))

 

Example 3

# This Python 3 code for 
# getting the maximum frequency 
# of character in string
  
# string initialization
input_str = "Msjackson"
  
# printing out the original string
print ("Original string is : " + input_str)
  
# naive method 
# getting the maximum frequency 
tot_freq = {}
for i in input_str:
    if i in tot_freq:
        tot_freq[i] += 1
    else:
        tot_freq[i] = 1
res = max(tot_freq, key = tot_freq.get) 
  
# printing out result 
print (" highest frequency character is : " + str(res))

 

More Posts

Find all occurrences of a character in a string python Tania - 16 hours
How to count number of character in a string python Tania - Jul 14
How to remove the last character of string in python. Tania - Jul 8
How to generate a random string in Python mhfaisal - Jul 10
How to count the number of characters in a string python mhfaisal - Jun 30
Number of characters in a string python Tania - May 27
How to print a string and a variable in python offonime - May 22
HOW TO REMOVE A SUBSTRING FROM STRING IN PYTHON - Oct 23, 2020
How to reverse a string in python amna - Oct 20, 2020
How to make a string all lowercase python offonime - Jun 26