Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

find frequency of each word in a string in python using dictionary

# the frequency of the word in a sentence by using dictionary
a=input("enter the string")
b={}
c=a.split()
for i  in c:
    if i not in b :
        b[i]=c.count(i)
    else:
        pass
print("frequency of the words in sentence")
for k in b:
    print(k,'-',b[k])
output:
'''
enter the string Today is a great day ,
great blue sky and energetic sun makes the day  better
frequency of the words in sentence
Today - 1
is - 1
a - 1
great - 2
day - 2
, - 1
blue - 1
sky - 1
and - 1
energetic - 1
sun - 1
makes - 1
the - 1
better - 1
'''
Comment

PREVIOUS NEXT
Code Example
Python :: drop null rows pandas 
Python :: presentation in jupyter notebook 
Python :: how to find word in file python 
Python :: how to set the size of a gui in python 
Python :: pandas create a column from index 
Python :: django httpresponseredirect 
Python :: np install python 
Python :: zermelo python 
Python :: python json parse 
Python :: python convert base 
Python :: create a dataframe with series 
Python :: install selenium python mac anaconda 
Python :: python bold text 
Python :: how to print for loop in same line in python 
Python :: get date and time python 
Python :: Select rows from a DataFrame based on column values? 
Python :: python negative infinity 
Python :: how to filter out all NaN values in pandas df 
Python :: how to install cuda in anaconda 
Python :: euclidean distance python 
Python :: how to exit the program in pygame 
Python :: splitting a string and appending each character to a list python 
Python :: how to say hello world 
Python :: train test validation sklearn 
Python :: view point cloud open3d 
Python :: jupyter notebook check memory usage 
Python :: how to access all the elements of a matrix in python using for loop 
Python :: static dir in django python 
Python :: How to convert text into audio file in python? 
Python :: one line input in python 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =