8. Lists
8.1. Before Kattis
Write a function
find_in_list(element, a_list) -> bool:
The function will
return
True
ifelement
exists within the lista_list
andFalse
otherwiseThis can use either a
for
loop or awhile
loop
Write a function
index_of(element, a_list) -> int:
The function will
return
the index of the first occurrence ofelement
within the lista_list
and-1
if it is not foundThis can use either a
for
loop or awhile
loop
Write a function
replace_all(the_list, find, replace):
This function will replace all occurrences of
find
withinthe_list
and replace them withreplace
This function must
return
the modified listFor example,
replace_all([1, 2, 2, 3], 2, 9)
->[1, 9, 9, 3]
Use the
replace_all
function to change the list[1, 2, 2, 1]
->[2, 1, 1, 2]
You will need to use
replace_all
multiple times