Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image

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. image

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

Step: 1

be useful consider how to keep track of the current index position while searching This could be a g... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Analytics Data Science And Artificial Intelligence Systems For Decision Support

Authors: Ramesh Sharda, Dursun Delen, Efraim Turban

11th Global Edition

1292341556, 9781292341552

More Books

Students also viewed these Programming questions

Question

Define culture in the context of clinical psychology.

Answered: 1 week ago

Question

Why must a truly smart home have a bot?

Answered: 1 week ago

Question

Define GDSS and list the limitations of the initial GSS software.

Answered: 1 week ago