示例代码:
Message = [[2,'Mike'],[1,'Jone'],[2,'Marry']]
dict1 = {}
for number in Message:
value = number[0]
if value not in dict1.keys():
dict1[value] = [number] #此句话玄机
else:
dict1[value].append(number)
print dict1
以此句话来分析:dict1[value] = [number]
如果number不加 [ ],那么结果就是:{1: [1, 'Jone'], 2: [2, 'Mike', [2, 'Marry']]} #这个数据结构不合格
number加了[ ] ,那么结果就是 :{1: [[1, 'Jone']], 2: [[2, 'Mike'], [2, 'Marry']]} #完美