Hello, I want to duplicate a list in python. The way I want is, I need two list with same content pointing to different memory Location. What I tried is

Dup_List = Original_List[:]

, but lookes like even this is making both list point to same memory location.

Both the List are 2D

Thanks in advance

Recommended Answers

No they are different lists with same items. If you want the items also as copies you should use deepcopy


Jump to Post

All 2 Replies

mylist1 = [1, 2, 3]

mylist2 = mylist1[:]


''' result show 2 different memory locations ...
Be a part of the DaniWeb community

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