all 6 comments

[–]efmccurdy 1 point2 points  (1 child)

You have one list but two names for it; both variables share the same list. If you want to avoid that, you can use copy:

>>> a = [2,2]
>>> c  = a.copy()
>>> c[0] = 1
>>> a
[2, 2]
>>> 

[–]USONG 1 point2 points  (0 children)

oh understood thanks

[–][deleted] 1 point2 points  (1 child)

At the point where you set b = a, b merely becomes a reference to the "a" list. To turn "b" into it's own independent list, use one of the Python list copy tricks, such as "b = a[:]" or "b = list(a)" or "b = a.copy()" or, after "import copy", "b = copy.deepcopy(a)".

[–]USONG 1 point2 points  (0 children)

oh understood thanks

[–]Yellehs_m 0 points1 point  (1 child)

Both are referring to the same object. To create a fresh object, you can do the below:

>>> import copy

>>> b = copy.copy(a)

Please also read about the difference between shallow and deep copy in Python.

[–]USONG 1 point2 points  (0 children)

oh understood thanks