我有 10 个元素的列表,其中包含 2 个元素的元组,我想为每个元组添加一个值,但是当我编写以下代码时,似乎计算了累积总和。这是怎么回事。请帮忙
# -*- coding: utf-8 -*-
i=0
k=10
count=[]
value=[1,2]
while i < k:
count.append(value)
i=i+1
t=[10,2]
i=0
#for item in count:
#print item
while i <(len(count)):
count[i][0]+=t[0];
count[i][1]+=t[1];
i+=1;
for item in count:
print item
outpus 即将出现
[101, 22]
[101, 22]
[101, 22]
[101, 22]
[101, 22]
[101, 22]
[101, 22]
[101, 22]
[101, 22]
[101, 22]
正如我所期望的那样
[11, 4]
[11, 4]
[11, 4]
[11, 4]
[11, 4]
[11, 4]
[11, 4]
[11, 4]
[11, 4]
[11, 4]