This code changes anum but it should not?? What is going wrong?
Many thanks

>>> astr=
>>> anum=[4,3,2,1]
>>> anew=anum
>>> for c,d in enumerate(anum):
... anew[c]=astr[c]
... print(anew,astr,anum)
...


>>>

This code changes anum but it should not?? What is going wrong?
Many thanks

>>> astr=
>>> anum=[4,3,2,1]
>>> anew=anum
>>> for c,d in enumerate(anum):
... anew[c]=astr[c]
... print(anew,astr,anum)
...


>>>

Use anew = list(anum) to make a copy, otherwise anew is only an alias for anum.

Edited 5 Years Ago by Gribouillis: n/a

Use anew = list(anum) to make a copy, otherwise anew is only a alias for anum.

Thank you very much.

This question has already been answered. Start a new discussion instead.