In: Computer Science
Python 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.
#function definition for wordsOfFrequence
#input-> words "string of strings", freq "integer"
#output -> list of strings have the frequency
def wordsOfFrequency(words,freq):
words4 = words.upper().split()
words = words.split()
words2 = []
words3 = []
result = []
for i in words:
if i not in words2 and i.upper() not in words3:
words2.append(i)
words3.append(i.upper())
for i in range(len(words2)):
if words.count(words2[i]) == freq or words4.count(words3[i]) == freq :
result.append(words2[i])
return result
words ='apple MaNgo apple Orange orange apple guava mango'
print(wordsOfFrequency(words,2))