Quantcast
Channel: How do I clone a list so that it doesn't change unexpectedly after assignment? - Stack Overflow
Viewing all articles
Browse latest Browse all 117

Answer by Code Carbonate for List changes unexpectedly after assignment. Why is this and how can I prevent it?

$
0
0

There is a simple technique to handle this.

Code:

number=[1,2,3,4,5,6] #Original listanother=[] #another empty listfor a in number: #here I am declaring variable (a) as an item in the list (number)    another.append(a) #here we are adding the items of list (number) to list (another)print(another)

Output:

>>> [1,2,3,4,5,6]

I hope this was useful for your query.


Viewing all articles
Browse latest Browse all 117

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>