7. Lists

  • Feel free to use your laptop if you have it

  • Ensure I have recorded your completion — failure to do so will result in a grade of 0

  • I strongly encourage you to work with others in the lab

    • When you get stuck, do me a favour and ask those sitting around you for help

    • I want people to get used to working together in the labs

    • Peer teaching and peer learning is super effective


To obtain full marks for the lab, you must:

  1. Have completed the pre-lab exercises

  2. Have been working on the lab content

  3. Demonstrate competency in the topics

7.1. Pre Lab Exercises


You must have completed the specified exercises prior to the start of the lab. If you have not come to lab prepared, you will be asked to leave and you will obtain a grade of 0 for the lab.

  • For all exercises

    • Do not make a vector.py file, just use Colab like you have been

    • Use assert to test instead of their test function

  1. Chapter 11 exercise(s)

    • 5

    • 6

7.2. Before Kattis

  1. Write a function linear_search(needle, haystack) -> bool:

    • The function will return True if needle exists within the list haystack and False otherwise

    • This can use either a for loop or a while loop

    • Write assert tests to verify correctness

  2. Write a function index_of(needle, haystack) -> int:

    • The function will return the index of the first occurrence of needle within the list haystack and -1 if it is not found

    • This can use either a for loop or a while loop

    • Write assert tests to verify correctness

  3. Write a function replace_all(the_list, find, replace):

    • This function will replace all occurrences of find within the_list and replace them with replace

    • This function must return the modified list

    • For example, replace_all([1, 2, 2, 3], 2, 9) -> [1, 9, 9, 3]

    • Write assert tests to verify correctness

  4. 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

    • Write assert tests to verify correctness

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

  1. https://open.kattis.com/problems/bijele

  2. https://open.kattis.com/problems/cold

  3. https://open.kattis.com/problems/nastyhacks

  4. https://open.kattis.com/problems/grassseed

  5. https://open.kattis.com/problems/pet

  6. https://open.kattis.com/problems/batterup

  7. https://open.kattis.com/problems/aboveaverage

  8. https://open.kattis.com/problems/icpcawards

  9. https://open.kattis.com/problems/quickbrownfox

  10. https://open.kattis.com/problems/nodup

  11. https://open.kattis.com/problems/conundrum

  12. https://open.kattis.com/problems/bela

  13. https://open.kattis.com/problems/kornislav


Ensure that your your completion has been recorded. Failure to do so may result in a grade of 0.