+ 1

How come I need to use the copy module to copy a mutable data structure?

I realized(the hard way) that to create copies of mutable data structures you can't just do this: a = [1,2,3,4] b = a You have to do this: import copy a = [1,2,3,4] b = copy.deepcopy(a) Why do I have to do that.

31st May 2019, 2:41 PM
0bhji
3 odpowiedzi
31st May 2019, 3:27 PM
Lothar
Lothar - avatar
+ 3
Huh. Never used that. I just do b = a[:]
31st May 2019, 4:47 PM
Choe
Choe - avatar
+ 1
Choe Wow. I never would have guessed. Thanks.
31st May 2019, 4:54 PM
0bhji