Python ??????? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python ???????

For shallow copy which one is the ideal method. lis=[1,2,3,4] lis2= lis.copy() OR import copy lis2 = copy.copy(lis)

19th Apr 2019, 5:52 PM
Dhanush
Dhanush - avatar
3 Answers
+ 2
Python 2 will expire soon anyway. Nonetheless, there are other simple ways to make a shallow copy: lis2 = list(lis1) lis2 = lis1[:] lis2 = [n for n in lis1]
19th Apr 2019, 6:17 PM
HonFu
HonFu - avatar
+ 1
When you can do something just using what the builtin types easily provide, it seems sensible to use just these.
19th Apr 2019, 6:12 PM
HonFu
HonFu - avatar
0
HonFu lis.copy() works in python3 only
19th Apr 2019, 6:14 PM
Dhanush
Dhanush - avatar