Trying to troubleshoot this code and am getting a bizarre output. Can someone explain why the outermost for loop is not running for i=2? Thanks!
For context, the code was written to try to delete all values in b from a, including all repeats (i.e. a=[1,2,2], b=[2] should output [1]). I know there are more efficient ways to do it I just am confused why this doesn't work.
Code:
def arrayfunc(a,b):
list = a
for i in a:
print(i)
for j in b:
if i == j:
list.remove(j)
print(a)
arrayfunc([1,2,3],[1])
Output
1
3
[2, 3]