Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to find most repeated word in a string in python

from collections import Counter

# Example phrase 
phrase = "John is the son of John second. Second son of John second is William second."
split_phrase = phrase.split()

# create counter object
Counter = Counter(split_phrase)

most_occured_words = Counter.most_common(4)
  
print(most_occured_words)
Comment

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 + "'.")
Comment

PREVIOUS NEXT
Code Example
Python :: Reason: Worker failed to boot 
Python :: python split 
Python :: similarity imdex in python 
Python :: python random number generator no duplicates 
Python :: css selenium 
Python :: for each loop python 
Python :: balancing paranthesis python 
Python :: python tkinter messagebox 
Python :: What does if __name_=="_main__": do? 
Python :: jupyter matplotlib 
Python :: assert integer python 
Python :: date time shit pandas 
Python :: How do I stop Selenium from closing my browser 
Python :: python get last item in a list 
Python :: deep learning with python 
Python :: installing python3.9 on linux mint 20 
Python :: how to change values in dataframe python 
Python :: group by dateime pandas 
Python :: how to make a bill in python 
Python :: percent in pandas 
Python :: how to take input of something in python 
Python :: matrix multiplication nupy 
Python :: load data python 
Python :: how to find the longest string python 
Python :: pyspark average group by 
Python :: edit models in django admin 
Python :: flask on gevent over https 
Python :: pandas remove whitespace 
Python :: list of dict to dict python 
Python :: python A string float numeral into integer 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =