Lesson 05-08: Building List Functions: replaceAll
¶
Learning Target: I can create a python function that will replace a given element in a list with another given element.
Assignment¶
In the area below, create a function called replaceAll()
that will take in three arguments:
original
- the original listfind_value
- the value you want to replace in the listreplace_with
- the value you want to replace it with in the list
and will replace ALL elements that in original
that match find_value
and replace their value with that of replace_with
. This function should modify the value of original
.
You may only use the following list methods: append()
, insert()
, remove()
, len()
.
Example:
replace([1,2,1,2],1,"a")
should return ["a",2,"a",2]
1
def replace(original,find_value,replace_with):
2
#write here
3
4
(cfu_0507_1)
removeall