我有10個元素的列表,其中包含2個元素的元組我想爲每個元組添加一個值,但是當我編寫下面的代碼時,似乎計算了累積和。這是怎麼發生的。請幫助列表修改如何在Python中工作
# -*- 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]
非常感謝..它幫助 – manyu
非常好@Keith –