Copying lists in python

0 votes
I have assigned a list to an older list. However, the new list changes too when I modify the older one. Why is this happening?
Apr 30, 2018 in Python by NEET
701 views

1 answer to this question.

0 votes

Assigning one list to another one simply means that both the lists will now refer to the same data. This is why any modifications to one of the lists gets reflected in the other one too. If you don't want this to happen, use copy.copy()

import copy
new_list = copy.copy(old_list)
answered Apr 30, 2018 by Nietzsche's daemon
• 4,260 points

Related Questions In Python

+1 vote
1 answer

Zip lists in Python

zip takes a bunch of lists likes a: ...READ MORE

answered Aug 22, 2018 in Python by Priyaj
• 58,020 points
858 views
0 votes
1 answer

How can I print Lists in python

print is a function in Python 3.x, so ...READ MORE

answered Oct 24, 2018 in Python by Priyaj
• 58,020 points
849 views
0 votes
5 answers
0 votes
1 answer

Pandas dataframe with multiple lists in Python

You can do it like this import pandas ...READ MORE

answered Apr 6, 2019 in Python by Esha
1,854 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,070 views
0 votes
1 answer

Difference between two lists in python

difference = list(set(list1) - set(list2)) READ MORE

answered May 24, 2018 in Python by Nietzsche's daemon
• 4,260 points
2,814 views
0 votes
1 answer

Using Lists and Tuples in Python

if you are familiar with C programming, ...READ MORE

answered May 29, 2018 in Python by Nietzsche's daemon
• 4,260 points
1,007 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP