How to copy a list in Python

4 Answers

0 votes
lst = [1, 2, 3, 4, 5]

lst_copy = lst.copy()

print(lst_copy)





'''
run:

[1, 2, 3, 4, 5]

'''

 



answered Apr 18, 2021 by avibootz
0 votes
lst = [1, 2, 3, 4, 5]

lst_copy = lst[:]

print(lst_copy)





'''
run:

[1, 2, 3, 4, 5]

'''

 



answered Apr 18, 2021 by avibootz
0 votes
lst = [1, 2, 3, 4, 5]

lst_copy = list(lst)

print(lst_copy)





'''
run:

[1, 2, 3, 4, 5]

'''

 



answered Apr 18, 2021 by avibootz
0 votes
lst = [1, 2, 3, 4, 5]

lst_copy = [i for i in lst]

print(lst_copy)





'''
run:

[1, 2, 3, 4, 5]

'''

 



answered Apr 18, 2021 by avibootz

Related questions

1 answer 139 views
1 answer 156 views
3 answers 219 views
219 views asked Nov 13, 2018 by avibootz
1 answer 179 views
4 answers 302 views
302 views asked Oct 30, 2017 by avibootz
1 answer 177 views
177 views asked Mar 25, 2017 by avibootz
...