1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
bogdanovich [222]
3 years ago
15

8.17 Lab: Strings of a Frequency Write a program that reads whitespace delimited strings (words) and an integer (freq). Then, th

e program outputs the strings from words that have a frequency equal to freq in a case insensitive manner.
Computers and Technology
1 answer:
gavmur [86]3 years ago
5 0

Answer:

def occurencesOfWords(words,freq):

  frequency_dictionary={}

  matched_frequency_words=[]

  for i in range(len(words)):

      counter=1

      a=words[i].lower()

      for j in range(len(words)):

          if(i==j):

              continue

          b=words[j].lower()

          if(a==b):

              counter+=1

      frequency_dictionary[words[i]]=counter

  for key in frequency_dictionary:

      if(frequency_dictionary[key]==freq):

          matched_frequency_words.append(key)

  return matched_frequency_words

if __name__=='__main__':

  user_input=input()

  freq=int(input())

  words=user_input.split(" ");

  required_words=occurencesOfWords(words,freq)

  for s in required_words:

      print(s)

Explanation:

  • Inside the occurencesOfWords function, initialize a frequency_dictionary that is used to store the string and the frequency of that specific string .
  • matched_frequency_words is an array that is used to store each string whose frequency matches with the provided frequency
  • Run a nested for loop up to the length of words and inside the nested for loop, skip the iteration if both variables i and j are equal as both strings are at same index.
  • Increment the counter variable, if two string are equal.
  • Loop through the frequency_dictionary to get the matching frequency strings .
  • Finally test the program inside the main function.
You might be interested in
100 points, PLEASE HELP...To generate numbers between and including -10 to 10 you would use:
Orlov [11]

Answer:

A number line?

6 0
3 years ago
vulnerability is a feebleness which allows an attacker to condense a system's information assurance to security,is it true or fa
Nookie1986 [14]
Hi
i just saw this question and i like to answer it
true
3 0
4 years ago
Web Services: a. Is a hardware application b. Is a software application c. Is an enterprise system d. Is a single database
Simora [160]

Answer:

9qoqoqoqoqooq0qqqqqqqq

7 0
3 years ago
HELP BRAINLST!!<br><br> How is labor already being automated in supermarkets?
11Alexandr11 [23.1K]

Answer:

Self-checkouts as well.

Explanation:

6 0
3 years ago
My friend has a battery of 9000mah and loses 10 every day how many days well it take to go to zero
forsale [732]
I think it's 900 but I can't be sure.
8 0
3 years ago
Other questions:
  • Write a SELECT statement that returns an XML document that contains all of the invoices in the Invoices table that have more tha
    8·1 answer
  • Which of these is an advantage of using the Clipboard task pane? A. You are able to apply OLE easily. B. There are more paste op
    15·2 answers
  • Which is a benefit of peer-to-peer networking?
    10·1 answer
  • What makes up an HTML element?
    12·2 answers
  • can you give me a tip to fix my SIM card becuaus when i put it on my phone it has no signal , can anyone fix this , thank you.​
    9·2 answers
  • A Windows user right-clicks on his desktop. What is he planning to do?
    10·1 answer
  • What is the Best IPTV service provider in the USA?
    9·1 answer
  • Because all the IEEE WLAN features are isolated in the PHY and ____________ layers, practically any LAN application will run on
    11·1 answer
  • Say yes if you hate edge2021?
    8·2 answers
  • If a pixel displayed on a screen has a red DN of 127, a green DN of 127, and a blue DN of 127, what color is the pixel
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!