Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python problem Write a function replace(s, old, new) that replaces all occurences of old with new in a string s. Your solution should pass the

Python problem

Write a function replace(s, old, new) that replaces all occurences of old with new in a string s. Your solution should pass the input/ouput tests in the "function_data" folder.

def replace(s, old, new) (6 points)

Hint: use string.split and string.join. """ # your code goes here def replace(s, old, new):

"""

Although Python provides us with many list methods, it is good practice and very instructive to think about how they are implemented. Implement a Python methods that works like the following:

a.count(obj, lst) # count method returns count of how many times obj occurs in list. (2 points) b.is_in(obj, lst) # cannot be called in() because "in" is a reserved keyword, so call it is_in, checks if all of the following items are in a list?(2 points) c.reverse(lst) # reverse the list(2 points) d.index(obj, lst) # finds the given element in a list and returns its position(2 points) e.insert(obj, index, lst) # insert an element at specific index in a list and return updated list(2 points)

Note: do NOT modify the original list!!! All your methods should return a number or a NEW LIST!

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

Which of the following is NOT a relational operator? 1. =

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago