Skip to content

Comment on Python: copying a list the right way

Comments

using list() in this manner feels a bit weird to me.

If you want to be truly explicit, why not use the built in copy module?

eg:

    from copy import copy
    b = copy(a)   #or deepcopy(), depending on your needs

*edit: I should note that the docs for copy suggest using the slice operator.
AboutSource Built by g1lg1l

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