Wednesday, 13 June 2018

To compute the frequency of the words from the input. The output should output after sorting the key alphanumerically.

# To compute the frequency of the words from the input. The output should
# output after sorting the key alphanumerically.

str = input("Enter a string : ")

if len(str)>0:
    dic = dict()
    wordList = str.split(" ")
    for w in wordList:
        dic.update({w:str.count(w)})
    dic = sorted(dic.items())
    print(dic)
else:
    print("String is empty.")

input("Press enter to exit.")

No comments:

Post a Comment

Popular Posts