Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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
'''
 
PREVIOUS NEXT
Tagged: #find #frequency #word #string #python #dictionary
ADD COMMENT
Topic
Name
6+6 =