Using Python, please write code that does the following:
Please try to keep it as simple as possible and cover all theconditions specified.
def mostCommonWords (filename, N): (20 points) Reads the file from filename in your function and returns a list of N most common words in the text file (i.e., N words with the highest frequency), sorted by the number of times they occured in the file (most common first). – Use wordFrequency() helper function to count the frequency of each word. – Print “[Error] The “<filename>” contains <x> unique words (you asked for <N>).” and return None if N is larger than the number of words in the file (substitute “<filename>”, <x>, <N> with the actual values). return “stub” Show transcribed image text def mostCommonWords (filename, N): (20 points) Reads the file from filename in your function and returns a list of N most common words in the text file (i.e., N words with the highest frequency), sorted by the number of times they occured in the file (most common first). – Use wordFrequency() helper function to count the frequency of each word. – Print “[Error] The “” contains unique words (you asked for ).” and return None if N is larger than the number of words in the file (substitute “”, , with the actual values). return “stub”
Expert Answer
Answer to Using Python, please write code that does the following: Please try to keep it as simple as possible and cover all the c…