Skip to content

Instantly share code, notes, and snippets.

@leangaurav
Created May 11, 2019 15:44
Show Gist options
  • Save leangaurav/0f6c5e965b7c1aa321131e35b87e6752 to your computer and use it in GitHub Desktop.
Save leangaurav/0f6c5e965b7c1aa321131e35b87e6752 to your computer and use it in GitHub Desktop.
import copy               # this is the module to use
l1 = [[10,20,30], 1, 2, 3]
l2 = copy.deepcopy(l1)             # create a copy using the deepcopy function from copy

l1.append(4)              # append to list l1
l1[0].append(40)          # modify the inner list of l1

print( l1 )
print( l2 )

Output
[[10, 20, 30, 40], 1, 2, 3, 4]
[[10, 20, 30], 1, 2, 3]

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