小编use*_*045的帖子

How to copy some elements from a list-of-list so that is doesn't affect the value of elements in the copied list

What I want to do is to copy some elements of one list-of-list to other based on certain conditions and then change the original list of lists

arr = [[1,0,4],[1,2,65],[2,3,56],[11,14,34]]
brr = []

for x in range(0,len(arr)):
    if arr[x][1] < 10:
        brr.append(arr[x])
        arr[x][1] = 1000
print(brr)
Run Code Online (Sandbox Code Playgroud)

O/P:

[[1, 1000, 4], [1, 1000, 65], [2, 1000, 56]]

in the above example, I wanted to copy all the list with the middle element <10 to another list-of-list brr and then change the …

python

2
推荐指数
1
解决办法
68
查看次数

标签 统计

python ×1