I think I do not understand how the .remove()
method works in Python.
I have this snippet. The point of the b
variable is to have an untouched copy of the a
list in every iteration, but it is not working as I expected:
a = [0, 1, 2, 3, 4, 5]
for i in a:
b = a.copy()
a_i = b.remove(i)
print(a_i)
I would expect the following outcome:
[1, 2, 3, 4, 5]
[0, 2, 3, 4, 5]
[0, 1, 3, 4, 5]
[0, 1, 2, 4, 5]
[0, 1, 2, 3, 5]
[0, 1, 2, 3, 4]
And instead I get:
None
None
None
None
None
Where is my misconception?
NOTE: I need an answer in a for loop format because this is a simplification of a bigger part of my code.
EDIT: The original version of the snippet had a b = a
line instead of b = a.copy()
. I corrected that (thanks) but I am still getting an array of None
's.