Reference no: EM132354829
Question
Write a function named zero_out that accepts two lists of integers a1 and a2 as parameters and replaces any occurrences of a2 in a1 with zeroes. The sequence of elements in a2 may appear anywhere in a1 but must appear consecutively and in the same order. For example, if variables called a1 and a2 store the following values:
a1 = [1, 2, 3, 4, 1, 2, 3, 4, 5]
a2 = [2, 3, 4]
The call of zero_out(a1, a2) should modify a1's contents to be [1, 0, 0, 0, 1, 0, 0, 0, 5]. Note that the pattern can occur many times, even consecutively. For the following two lists a3 and a4:
a3 = [5, 5, 5, 18, 5, 42, 5, 5, 5, 5]
a4 = [5, 5]
The call of zero_out(a3, a4) should modify a3's contents to be [0, 0, 5, 18, 5, 42, 0, 0, 0, 0].
You may assume that both lists passed to your function will have lengths of at least 1. If a2 is not found in a1, or if a1's length is shorter than a2's, then a1 is not modified by the call to your function. Please note that a1's contents are being modified in place; you are not supposed to return a new list. Do not modify the contents of a2.