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

8.1. Pre Lab Exercises

  • 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

  2. Write assertion tests for each of your functions above

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

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