我正在尝试更改 z list 的列表元素的最后一个索引处的元素,但出现错误
l=['n1','n2','n3','n4']
path=['x','n1','y','z','n2']
y = ['n']
path+= y
d=0
seen = set()
for i in l:
if i in path:
f=0
else:
d+=1
seen.add(i)
n=0
z = [[]]*d
for i in seen:
z[n] = path
z[n][-1] = i
n+=1
print(z)
z 应该
[['x', 'n1', 'y', 'z', 'n2', 'n3'], ['x', 'n1', 'y', 'z', 'n2', 'n4']]
但n3它只给出了列表元素的最后一个索引,即
[['x', 'n1', 'y', 'z', 'n2', 'n3'], ['x', 'n1', 'y', 'z', 'n2', 'n3']]
我无法弄清楚为什么它没有给出正确的结果。
呼啦一阵风
相关分类