Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Task Write a file named str_redux.py that implements versions of the string methods find and split without using any string methods or functions. In particular,

Task

Write a file named str_redux.py that implements versions of the string methods find and split without using any string methods or functions.

In particular, define a function myfind such that myfind(s,t) does the same thing that s.find(t) does; and a function mysplit such that mysplit(s,t) does the same thing that s.split(t) does.

You may not use any string methods in your solution. All operators (including in, [index], [i1:i2], etc) are fair game. None of the functions (nor the file itself) should print anything nor ask for any input.

In addition to functional correctness, some points will be reserved for

having good variable names

having meaningful docstrings for all functions you write

2Example Invocations

When you run str_redux.py, nothing should happen. It defines a function, it does not run it.

If in another file (which you do not submit) you write the following:

import str_redux print(str_redux.myfind('divided','d')) print(str_redux.myfind('divided','id')) print(str_redux.myfind('divided','ido')) print() print(str_redux.mysplit('divided','d')) print(str_redux.mysplit('divided','id')) print(str_redux.mysplit('divided','ido')) 

you should get the following output:

0 3 -1 ['', 'ivi', 'e', ''] ['div', 'ed'] ['divided'] 

3Troubleshooting

myfind is simpler than, and will help prepare you for, mysplit. We suggest getting myfind working properly before starting on mysplit.

Did you test the edge cases of first- and last-characters? i.e., can you find both the h and oin 'hello'?

Youll likely find that mysplit is easier to write by calling myfind within it.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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_2

Step: 3

blur-text-image_3

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

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions

Question

2. What is the basis for the rhythmicity observed in cells?

Answered: 1 week ago

Question

Consistently develop management talent.

Answered: 1 week ago

Question

Create a refreshed and common vision and values across Europe.

Answered: 1 week ago