Ask Question
26 July, 22:44

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

+5
Answers (1)
  1. 26 July, 23:25
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers