+ 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.
3 Réponses
+ 5
A real good answer can be found here:
https://www.geeksforgeeks.org/copy-JUMP_LINK__&&__python__&&__JUMP_LINK-deep-copy-shallow-copy/
+ 3
Huh. Never used that. I just do
b = a[:]
+ 1
Choe
Wow. I never would have guessed.
Thanks.