Skip to content

Instantly share code, notes, and snippets.

@IndhumathyChelliah
Created August 31, 2021 02:04
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/a9c0e685fb78b1876aa2bf74fda5803f to your computer and use it in GitHub Desktop.
Save IndhumathyChelliah/a9c0e685fb78b1876aa2bf74fda5803f to your computer and use it in GitHub Desktop.
original_list=[1,2,3,[4,5]]
#Copying list using list comprehension
copied_list=original_list.copy()
print(copied_list)
#Output:[1, 2, 3, [4, 5]]
print(original_list)
#Output:[1, 2, 3, [4, 5]]
#modifying original_list
original_list[3].append(6)
print(original_list)
#Output:[1, 2, 3, [4, 5, 6]]
print(copied_list)
#Output:[1, 2, 3, [4, 5, 6]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment