replacing items in nested lists python

前端 未结 5 1368
死守一世寂寞
死守一世寂寞 2021-01-16 07:04

I am trying to make a duplicate list of lists and change one element to another within the nested lists of the duplicate list but am having some trouble. How I made the dup

5条回答
  •  孤街浪徒
    2021-01-16 07:38

    It seems that, as with many other languages, arrays are no more than constants (not even actual pointers although that might be different in python). Rather, The address of the first element of the array is constant. This means that if you would directly copy the array, you would only copy the address of the first element.

    From your question, I understand that you want a deep copy. That means that, you also need to copy the contents of you nested arrays. You can use copy.deepcopy(x) to make a deepcopy of the array.

    Check out the copy module for more in-depth information.

自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题