I wanted to create a code that printed the frequency of words in a string and I did but I had a little problem though. Here's the code:
string=input("Enter your string: ")
string=string.split()
a=0
while(a<len(string)):
print (string[a], "=", string.count(string[a]))
a=a+1
Everything ran fine but if a word occurred twice, it'd say the word and state the occurrence in two places. I really need help here. Thanks!
collections.Counter()does exactly what you are looking for.