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.

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

Thank you very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.