Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

most repeated character in a string python

### Has No Modules ###

# The string
string = input("What 'thing' do you want the most repeated character of? Just type it!: ")

# Setting an empty dictionary (Key = Character + Value = Frequency)
character_frequency = {}

for character in string:
  if character in character_frequency:
    character_frequency[character] += 1
  else:
    character_frequency[character] = 1

    
Values = sorted([kv[1] for kv in character_frequency.items()], reverse=True)

for k,v in character_frequency.items():
  if v == Values[0]:
    print("'" + k + "'", "is the most repeated character in '" + string + "'.")
 
PREVIOUS NEXT
Tagged: #repeated #character #string #python
ADD COMMENT
Topic
Name
9+3 =