How to deep copy a list?

前端 未结 8 1471
旧巷少年郎
旧巷少年郎 2020-11-22 03:07

I have some problem with a List copy:

So After I got E0 from \'get_edge\', I make a copy of E0 by calling \'E0_copy =

8条回答
  •  耶瑟儿~
    2020-11-22 03:37

    If the contents of the list are primitive data types, you can use a comprehension

    new_list = [i for i in old_list]
    

    You can nest it for multidimensional lists like:

    new_grid = [[i for i in row] for row in grid]
    

提交回复
热议问题