Given a sentence S, write a program to print the frequency of each word in S, where words are sorted in alphabetical order.
S = input()
words = {}
for w in S.split():
if w in words:
words[w] += 1
else:
words[w] = 1
for w in sorted(words):
print("%s:\t%s" % (w, words[w]))
Comments
Leave a comment