Ask Question
13 June, 12:43

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'.

+1
Answers (1)
  1. 13 June, 14:42
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers