Write a program to compute the frequency of the words from the input. The output should output after sorting the key alphanumerically.
Topic: Write a program to compute the frequency of the words from the input. The output should output after sorting the key alphanumerically.
Solution
freq = {} # frequency of words in text line = input() for word in line.split(): freq[word] = freq.get(word,0)+1 words = freq.keys() words.sort() for w in words: print("%s:%d" % (w,freq[w]))
List all Python Programs