0
Output question.
Why is the output of the following code = [1,[2,5]]? a= [1,[2,3]] b= a[:] a[0] = 3 a[1][1] = 5 print(b)
4 Réponses
+ 3
b = a[:]
copies all indexes to b, since a[1] is a list the refernce to that list get copied. when you now edit a[1] the change is in b too.
you perhaps should use:
import copy
b = copy.deepcopy(a)
+ 2
Sorry about that, that was my first question, I didn't think about that, my bad
+ 1
Please mention the language in Relevant Tags rather than a sentence or question 'why on the following scrip,'. Proper use of tags helps improve search feature quality 👍
0
I understand, just reminding you in case you forget, no problem buddy 👍