Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part I: You Haven't Seen the Last of Me! (4 points) Complete the removeLast function, which takes two string arguments. This function returns a new

image text in transcribed
Part I: You Haven't Seen the Last of Me! (4 points) Complete the removeLast function, which takes two string arguments. This function returns a new string based on the first string argument, with the following modification: the last occurrence of each letter from the second string has been removed (if a given letter appears n times in the second string, up to the last n occurrences of that letter will be removed from the first string. depending on the number of times that letter appears in the first string) Your basic strategy should be to process the second string argument, character by character. For each character, locate its last occurrence within the first string argument (we suggest using Python's rfind () method, described in the lecture slides). If the character is present, remove the rightmost copy of that character from the first string argument. When you have processed every character in the second string argument, return whatever is left of the first string argument. Please note that: characters in the second string are NOT guaranteed to appear in the first string in the same numbers (or at all there is NO guarantee regarding the relative lengths of the two strings removeLast 0 is CASE-SENSITIVE; it only removes characters from the first string if they appear in the same case as they do in the second string For example, consider the strings "quicksilver and blink": 1. The first letter of "blink" ("b") does not appear in "quicksilver", so we move on 2The second letter of "blink" ("I") appears in "quicksilver", so we remove the last (and in this case, only) occurrence to get "quicksiver" 3. The third letter of-blink 4. The fourth letter of "blink" "n) does not appear in "quicksver", so we move on 5. The final letter of "blink" (k") appears in "quicksver", so we remove it to get "quicsver as our final answer ("i ) appears twice in quick siver : we remove the last right most) instance to get quick ser Hint: Remember that Python strings are immutable, they cannot be modified directly. In order to remove a character from a string, you will need to construct a new string (most likely using slicing) and assign it to the old string variable, replacing the original. We have provided a stub for a helper function named exciseO that you may wish to call from within your

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

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

More Books

Students also viewed these Databases questions

Question

=+What do you want them to know?

Answered: 1 week ago