Python 即使条件不是true,列表值也会在if语句中更新

Python 即使条件不是true,列表值也会在if语句中更新,python,Python,我试图扫描矩阵中某个特定索引(firstCord)的八个相邻索引,并找出其任何相邻索引是否存在于另一个列表(Cord)中,该列表包含一些作为元素的随机坐标。如果它的任何邻居出现在Cord列表中,那么我会将该特定坐标附加到Temp_Cord列表中。下面给出了代码片段 我可以看到,当第一次满足if newCord in Cord:条件时,Temp\u Cord会附加newCord值。这是预期的行为。但是,Temp\u-Cord中的附加值会根据newCord中的更改而在每隔一次迭代中更改,这就像Tem

我试图扫描矩阵中某个特定索引(
firstCord
)的八个相邻索引,并找出其任何相邻索引是否存在于另一个列表(
Cord
)中,该列表包含一些作为元素的随机坐标。如果它的任何邻居出现在
Cord
列表中,那么我会将该特定坐标附加到
Temp_Cord
列表中。下面给出了代码片段

我可以看到,当第一次满足
if newCord in Cord:
条件时,
Temp\u Cord
会附加
newCord
值。这是预期的行为。但是,
Temp\u-Cord
中的附加值会根据
newCord
中的更改而在每隔一次迭代中更改,这就像
Temp\u-Cord[0]
newCord
共享相同的内存一样。有人能帮我解决这个问题吗。只有当
如果newCord in Cord:
条件为真时,我才需要使用
newCord
值附加
临时电源线

先谢谢你

Cordlen = len(Cord)
orientation = [(-1,0), (-1,1), (0,1), (1,1), (1,0), (1,-1),(0,-1),(-1,-1)]
firstCord = [0,173]
Temp_Cord = []
while ((Arrlen) < Cordlen):

    newCord = [0,0]   

    for i in orientation:
        newCord[0] = firstCord[0] + i[0]
        newCord[1] = firstCord[1] + i[1]

        if newCord in Cord:
            Temp_Cord.append(newCord)

    Arrlen = len (Temp_Cord) 
Cordlen=len(跳线)
方向=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
firstCord=[0173]
温度线=[]
而((Arrlen)
您在一次又一次地添加相同的列表

为什么不像这样使用
tuple

for i in orientation:
    newCord = firstCord[0] + i[0], firstCord[1] + i[1]
或者,如果它需要成为一个
列表
,则每次都要创建一个新列表

for i in orientation:
    newCord = [firstCord[0] + i[0], firstCord[1] + i[1]]