Given a sentence S, write a program to print the frequency of each word in S, where words are sorted in alphabetical order.
words = {}
for str in input().split():
word = ("".join([ c if c.isalnum() else "" for c in str ]))
if word not in words:
words[word] = 1
else:
words[word] += 1
for word in sorted(words):
print(word, ": ", words[word], sep='
Comments
Leave a comment