Knowee
Questions
Features
Study Tools

There is a collection of input strings and a collection of query strings. For each query string, determine how many times it occurs in the list of input strings. Return an array of the results.ExampleThere are instances of '', of '' and of ''. For each query, add an element to the return array, .Function DescriptionComplete the function matchingStrings in the editor below. The function must return an array of integers representing the frequency of occurrence of each query string in stringList.matchingStrings has the following parameters:string stringList[n] - an array of strings to searchstring queries[q] - an array of query stringsReturnsint[q]: an array of results for each queryInput FormatThe first line contains and integer , the size of .Each of the next lines contains a string .The next line contains , the size of .Each of the next lines contains a string .Constraints .Contest ends in 2 hoursSubmissions: 86Max Score: 10Difficulty: MediumRate This Challenge: More Python 31#!/bin/python32​3import math4import os5import random6import re7import sys8​9#10# Complete the 'matchingStrings' function below.11#12# The function is expected to return an INTEGER_ARRAY.13# The function accepts following parameters:14# 1. STRING_ARRAY stringList15# 2. STRING_ARRAY queries16#17​18def matchingStrings(stringList, queries):19    # Write your code here20​21if __name__ == '__main__':22    fptr = open(os.environ['OUTPUT_PATH'], 'w')23​24    stringList_count = int(input().strip())25​26    stringList = []27​28    for _ in range(stringList_count):29        stringList_item = input()30        stringList.append(stringList_item)31​32    queries_count = int(input().strip())33​34    queries = []35​36    for _ in range(queries_count):37        queries_item = input()38        queries.append(queries_item)39​40    res = matchingStrings(stringList, queries)41​42    fptr.write('\n'.join(map(str, res)))43    fptr.write('\n')44​45    fptr.close()46​

Question

There is a collection of input strings and a collection of query strings. For each query string, determine how many times it occurs in the list of input strings. Return an array of the results.ExampleThere are instances of '', of '' and of ''. For each query, add an element to the return array, .Function DescriptionComplete the function matchingStrings in the editor below. The function must return an array of integers representing the frequency of occurrence of each query string in stringList.matchingStrings has the following parameters:string stringList[n] - an array of strings to searchstring queries[q] - an array of query stringsReturnsint[q]: an array of results for each queryInput FormatThe first line contains and integer , the size of .Each of the next lines contains a string .The next line contains , the size of .Each of the next lines contains a string .Constraints .Contest ends in 2 hoursSubmissions: 86Max Score: 10Difficulty: MediumRate This Challenge: More Python 31#!/bin/python32​3import math4import os5import random6import re7import sys8​9#10# Complete the 'matchingStrings' function below.11#12# The function is expected to return an INTEGER_ARRAY.13# The function accepts following parameters:14# 1. STRING_ARRAY stringList15# 2. STRING_ARRAY queries16#17​18def matchingStrings(stringList, queries):19    # Write your code here20​21if name == 'main':22    fptr = open(os.environ['OUTPUT_PATH'], 'w')23​24    stringList_count = int(input().strip())25​26    stringList = []27​28    for _ in range(stringList_count):29        stringList_item = input()30        stringList.append(stringList_item)31​32    queries_count = int(input().strip())33​34    queries = []35​36    for _ in range(queries_count):37        queries_item = input()38        queries.append(queries_item)39​40    res = matchingStrings(stringList, queries)41​42    fptr.write('\n'.join(map(str, res)))43    fptr.write('\n')44​45    fptr.close()46​

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The provided text is a Python code. It's a problem statement where you need to complete the function matchingStrings(stringList, queries). This function should return an array of integers representing the frequency of occurrence of each query string in stringList.

Here is a step-by-step guide to solve this problem:

  1. First, understand that stringList is a list of strings where we will search for the queries, and queries is a list of strings that we will search for in stringList.

  2. We need to iterate over each query in queries and count how many times it appears in stringList. We can use the count() method of a list in Python, which returns the number of times a specific element appears in the list.

  3. For each query, we append the count to a result list res.

  4. Finally, we return the result list res.

Here is the completed function:

def matchingStrings(stringList, queries):
    res = []
    for query in queries:
        res.append(stringList.count(query))
    return res

This function works by iterating over each query and counting its occurrences in stringList using the count() method. The count is then appended to the result list res. After all queries have been processed, res is returned.

This problem has been solved

Similar Questions

Complete the find_string(sentence, string_to_find) function that takes two string parameters, namely sentence and string_to_find. This function should return the number of times that the parameter, string_to_find, appears in the sentence.

Ram is a supermarket employee. He works in the stock maintenance department. He wants to determine how frequently these items are repeated. Assist developers in writing code to address the problem.Input format :The first line of the input consists of the number of productThe second line of the input consists of the product nameThe third line of the input consists of the searched element.Output format :The output displays the frequency of the searched element.Refer to the sample input and output for format specifications.Sample test cases :Input 1 :7milkfruit breadjammilkeggsFrozen FoodsCheesemilkOutput 1 :2

We are given a function countWordOccurrences that takes two string parameters sentence and word."Sentence" is a string made up of multiple words separated by spaces.We have to find how many times 'word' occurs in the given 'sentence'.The 'word' should be an exact match.Note: The case (uppercase/lowercase) of the letters in the word does NOT matter.InputFirst line contains space separated series of words which represents the string "sentence".Second line contains a single word "word".Constraints1 ≤ length(sentence), length(word) ≤ 104length(word) ≤ length(sentence)OutputWe have to return an integer which is the number of occurrences of the single word 'word' in the string 'sentence'.

Suppose that an array of strings contains ["blueberry", "chocolate", "coconut", "coffee", "mint", "strawberry", "vanilla"]. How many compares are used for a successful search for "mint" with sequential search?1 point23456

Define the function count_substring(string, substring) that finds how many times the substring appears in the given string.Example:string = "Python is a powerful language. I want to learn Python"substring = "Python"Expected Output:2

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.