Ask Question

g Define a function called most_frequent_letter which takes no arguments. This function will return a dictionary which will have as keys the words in the file words. txt and values the most frequent letter occurring in the word. So for the word 'hello' the value will be 'l'.

+3
Answers (1)
  1. 24 July, 09:26
    0
    def most_frequent_letter ():

    file = open ("words","r")

    dWords = {}

    for line in file:

    line = line. rstrip ()

    words = line. split (" ")

    for word in words:

    counts = {}

    for c in word:

    counts[c] = counts. get (c, 0) + 1

    dWords[word] = max (counts, key=counts. get)

    return dWords

    print (most_frequent_letter ())

    Explanation:

    the file used was words in txt format and its contents are as follows:

    hello aamir jan khan

    parallelogram abdullah

    anaconda ali

    pycharm notebook
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “g Define a function called most_frequent_letter which takes no arguments. This function will return a dictionary which will have as keys ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers