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 150 views
1 answer 168 views
3 answers 232 views
232 views asked Nov 13, 2018 by avibootz
1 answer 195 views
4 answers 323 views
323 views asked Oct 30, 2017 by avibootz
1 answer 194 views
194 views asked Mar 25, 2017 by avibootz
...