Skip to content

Comment on Python: copying a list the right wayparent

Comments

You can't say just looking at b[:] that its creates a copy unless you know its type e.g., if `b` is a numpy array then it doesn't copy the data and by changing b[i] you change a[i].

list(a), copy.copy(a) are more explicit.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.