Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created July 26, 2020 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndhumathyChelliah/a7f220d9553f77817e08fdb04cd99d78 to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/a7f220d9553f77817e08fdb04cd99d78 to your computer and use it in GitHub Desktop.
from copy import copy
x=[1,2,[3,4]]
#Copying x
y=copy(x)
#Modifying elemets in the outer list
#Changes are not reflected in the copied list
x[0]=99
print (x)#Output:[99, 2, [3, 4]]
print (y)#Output:[1, 2, [3, 4]]
#Modifying elements in the nested list.
#Changes are reflected in the copied list also.
x[2][0]=5555
print (x)#Output:[99, 2, [5555, 4]]
print (y)#Output:[1, 2, [5555, 4]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment