Because lists are mutable it is possible to write functions that manipulate lists without returning anything. To demonstrate your understanding of mutable lists, write a function that removes objects from a list.
Details
Write a function called remove_all(a_list, item)
. The
function should modify a_list
to remove all items in
the list that are equal to item
without changing the
order of the other items. Note that the function should not return
anything. Be careful iterating over a list while removing from it.
Make sure your program handles all necessary cases gracefully. What additional test cases should you check?
Example
>>> my_list = [1, 2, 3, 2, 1] >>> remove_all(my_list, 2) >>> print(my_list) >>> [1, 3, 1]
Submission
Submit your program as a .py file on the course Inquire page before class on Monday November 3rd.