Changing one list unexpectedly changes another, too [duplicate]

Why does v change at all?

vec and v are both references.

When coding vec = v you assign v address to vec.
Therefore changing data in v will also “change” vec.

If you want to have two different arrays use:

vec = list(v)

Leave a Comment