例子如下:
test = ([1],[2])
test[0][0] = 8
test
([8], [2])
t = ([0],)*5
w = {w:{'统计树':t, 'ind':ind} for ind,w in enumerate(['a','b','c'])}
w
{'a': {'统计树': ([0], [0], [0], [0], [0]), 'ind': 0},
'b': {'统计树': ([0], [0], [0], [0], [0]), 'ind': 1},
'c': {'统计树': ([0], [0], [0], [0], [0]), 'ind': 2}}
w['a']['统计树'][0][0] = 3
w
{'a': {'统计树': ([3], [3], [3], [3], [3]), 'ind': 0},
'b': {'统计树': ([3], [3], [3], [3], [3]), 'ind': 1},
'c': {'统计树': ([3], [3], [3], [3], [3]), 'ind': 2}}
新建包含list的元祖,可以先生成list,再转为元祖,如下:
test2 = [[i] for i in range(5)]
test2
[[0], [1], [2], [3], [4]]
tuple(test2)
([0], [1], [2], [3], [4])
test2[2][0] = 9
test2
[[0], [1], [9], [3], [4]]