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.pyfile, just use Colab like you have beenUse
assertto test instead of theirtestfunction
-
5
6
7
8
Write assertion tests for each of your functions above
7.2. Before Kattis
Write a function
linear_search(needle, haystack) -> bool:The function will
returnTrueifneedleexists within the listhaystackandFalseotherwiseThis can use either a
forloop or awhileloopWrite
asserttests to verify correctness
Write a function
index_of(needle, haystack) -> int:The function will
returnthe index of the first occurrence ofneedlewithin the listhaystackand-1if it is not foundThis can use either a
forloop or awhileloopWrite
asserttests to verify correctness
Write a function
replace_all(the_list, find, replace):This function will replace all occurrences of
findwithinthe_listand replace them withreplaceThis function must
returnthe modified listFor example,
replace_all([1, 2, 2, 3], 2, 9)->[1, 9, 9, 3]Write
asserttests to verify correctness
Use the
replace_allfunction to change the list[1, 2, 2, 1]->[2, 1, 1, 2]You will need to use
replace_allmultiple 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