8. Lists

8.1. Before Kattis

  1. Write a function find_in_list(element, a_list) -> bool:

    • The function will return True if element exists within the list a_list and False otherwise

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

  2. Write a function index_of(element, a_list) -> int:

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

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

  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]

  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