Skip to content

Commit 3cf5ca8

Browse files
authored
Create Clone.py
Using slicing technique This is the easiest and the fastest way to clone a list. This method is considered when we want to modify a list and also keep a copy of the original. In this we make a copy of the list itself, along with the reference. This process is also called cloning. This technique takes about 0.039 seconds and is the fastest technique.Output: Original List: [4, 8, 2, 10, 15, 18] After Cloning: [4, 8, 2, 10, 15, 18]
1 parent 8e86b94 commit 3cf5ca8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Clone.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def Cloning(li1):
2+
li_copy = li1[:]
3+
return li_copy
4+
5+
# Driver Code
6+
li1 = [4, 8, 2, 10, 15, 18]
7+
li2 = Cloning(li1)
8+
print("Original List:", li1)
9+
print("After Cloning:", li2)

0 commit comments

Comments
 (0)