看别人代码的时候,偶然发现,python的list扩展居然可以简单地用乘法实现:
[0] * 3 = [0,0,0]
[0,0] * 3 = [0,0,0,0,0,0]
[[0,0]] * 3 = [[0,0], [0,0], [0,0]]
我要实现的目的是:
count = [[0,0]] * 3
# fields set : no, x1, x2
for i in range(3):
no,x1,x2 = fields.split(',')
count[int(no)][0] += x1
count[int(no)][1] += x2
结果统计出来的值居然是:
count[0],count[1],count[2]永远相等
这个。。。。
不是个bug,也是个坑啊。