Skip to content

Instantly share code, notes, and snippets.

@rohityadavcloud
Created July 14, 2015 15:12
Show Gist options
  • Save rohityadavcloud/fe85fb02e1a7fda2fd2d to your computer and use it in GitHub Desktop.
Save rohityadavcloud/fe85fb02e1a7fda2fd2d to your computer and use it in GitHub Desktop.
deepcopy vs list
import copy
a = 1
b = [1,2,3]
c = "Some random string :)"
z = [a,b,c]
x = list(z)
x[1][1] = 100
print x
print z
@rohityadavcloud
Copy link
Author

Why list() is wrong, because x == z

In [37]: print x
[1, [1, 100, 3], 'Some random string :)']

In [38]: print z
[1, [1, 100, 3], 'Some random string :)']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment