7. Lists
Feel free to use your laptop
You are strongly encourage to work with others
When you get stuck, ask those sitting around you for help
Get used to working together in the labs
Peer teaching and peer learning has been empirically shown to be very effective
7.1. Pre Lab Exercises
For all exercises
Do not make a
vector.py
file, just use Colab like you have beenUse
assert
to test instead of theirtest
function
-
5
6
Write assertion tests for each of your functions above
7.2. Before Kattis
Write a function
linear_search(needle, haystack) -> bool:
The function will
return
True
ifneedle
exists within the listhaystack
andFalse
otherwiseThis can use either a
for
loop or awhile
loopWrite
assert
tests to verify correctness
Write a function
index_of(needle, haystack) -> int:
The function will
return
the index of the first occurrence ofneedle
within the listhaystack
and-1
if it is not foundThis can use either a
for
loop or awhile
loopWrite
assert
tests to verify correctness
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]
Write
assert
tests to verify correctness
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
7.3. Kattis Problems
You should be using a scrap piece of paper to work out the ideas for the following problems
The problems you are to solve are getting too complex to try to solve by just coding
Trying to solve problems by just typing away will not yield success