Question: [10 points] PYTHON: Develop a program to replace parts of the string. Write a function replace(s, old, new) that replaces all occurrences of old with

  1. [10 points] PYTHON: Develop a program to replace parts of the string.

Write a function replace(s, old, new) that replaces all occurrences of old with new in the string s. It returns the modified string. Dont use the built-in replace function.

No global variables are used in the function. Function parameters must be used. NO LOOP. USE SPLIT AND JOIN METHOD.

Example:

print(replace('Mississippi', 'i', 'I')) #Output: 'MIssIssIppI' s = 'I love spom! Spom is my favorite food. Spom, spom, spom, yum!' print(replace(s, 'om', 'am')) #Output: 'I love spam! Spam is my favorite food. Spam, spam, spam, yum!')

Hint: use the split and join methods.

Hint: NO LOOP

Hint: No global variables are used in the function.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!