8.17 Lab: Strings of a Frequency Write a program that reads whitespace delimited strings (words) and an integer (freq). Then, the program outputs the strings from words that have a frequency equal to freq in a case insensitive manner. Your specific task is to write a function wordsOfFreqency(words, freq), which will return a list of strings (in the order in which they appear in the original list) that have a frequency same as the function parameter freq. The parameter words to the function wordsOfFreqency(words, freq) should be a list data structure. If two strings in the list words contain the same sequence of characters but are different case, they are considered the same. For example, we will consider the strings UCONN and uconn to be the same. Test cases 1-4

Respuesta :

Answer:

def wordsOfFreqency(words, freq):

 text1 = "Apple apPLE mangO aPple orange Orange apple guava Mango mango"

 words = []

 words1 = []

 words1 = text1.split()

 words = [x.upper() for x in words1]

 freq=[words.count(w) for w in words]

 print(dict(zip(freq,words)))

 return words

def main():

wordsOfFreqency(words, freq)      

if __name__=="__main__":

main()    # call main function

Explanation:

This will print the list of strings as per its word frequency.

Output is :

{4: 'APPLE', 3: 'MANGO', 2: 'ORANGE', 1: 'GUAVA'}

ACCESS MORE
EDU ACCESS