Clone / Copy List
Create a shallow copy of a list.
BeginnerTopic: List Programs
Python Clone / Copy List Program
This program helps you to learn the fundamental structure and syntax of Python programming.
# Program to clone a list
items = input("Enter list elements separated by space: ").split()
clone1 = items[:]
clone2 = list(items)
print("Original:", items)
print("Clone1:", clone1)
print("Clone2:", clone2)Output
Enter list elements separated by space: a b c Original: ['a', 'b', 'c'] Clone1: ['a', 'b', 'c'] Clone2: ['a', 'b', 'c']
Understanding Clone / Copy List
We demonstrate two common shallow-copy techniques: slicing and passing to list().
Note: To write and run Python programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Python Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Python programs.