I wanted to make a copy of a list in python while also removing one element:
x = [1,2,3]
a = list(x).remove(2)
While x
was still [1,2,3]
as expected, a
was None
instead of the [1,3]
that I expected.
I get the expected behavior if I break line 2 into two lines:
x = [1,2,3]
a = list(x)
a.remove(2)
a
is now [1,3]
with x unmodified.
Why is this?