Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started