Question: There are many facets to working with strings in data. This includes comparing strings or finding specific characters, words, or phrases. More advanced usage of

There are many facets to working with strings in data. This includes comparing strings or finding specific characters, words, or phrases. More advanced usage of textual data includes authorship analysis with the imposter algorithm or assessing sentiment in business reviews. Another example is the count of keywords in the search engine page ranking.

Problem One

Currently, I have no way to count the number of times a substring matches within another string. To solve this problem, I will need to create two functions: countSubstrMatches and countSubstrRecursive. Both of these functions will take two arguments: a string to search and the substring you want to find.

def countSubstrMatches (srch_str, sub_str): Describe what the function does, what type of

The functions will both use the method find to identify the matches. The first function will search iteratively. The second function will search recursively. While working on creating these functions, it must import the string library, understand the use of find, and understand the difference between iteration and recursion. After the comments needed in every script file, add from string import * to the script file so that we have access to the built-in string functions in base Python. When using the method find, we must have a string to search and a substring to find. There are optional arguments, as well. Optionally, we can also provide the start and stop index values. When we use this method, it returns a number. If the value return is a negative one, no matches were found. Alternatively, the returned value is the index position of the first match. There are examples of the usage, input, and output of this method shown in Figure 2. information goes into the arguments, and what is returned. def countSubstrRecursive (srch_str,

Ensure assumptions are not made regarding the string that is going to be searched. This string could be a word, phrase, novel, or nonsense. When working on the function that will search recursively, think about how to break this problem down into smaller pieces. Adding an optional argument to the function might be helpful. If  wondering what optional argument would be useful here, consider how  processed the string in the iterative function.

def countSubstrMatches (srch_str, sub_str): Describe what the function does, what type of information goes into the arguments, and what is returned. def countSubstrRecursive (srch_str, sub_str): Describe what the function does, what type of information goes into the arguments, and what is returned.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

be useful consider how to keep track of the current index position while searching This could be a g... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!