首页 > 代码库 > Python中字典嵌套??

Python中字典嵌套??

如dict={1:‘a‘,2:‘b‘},要得到一个字典dict={1:‘a‘,2:‘b‘,3:{1:‘a‘,2:‘b‘}}

 1 >>> dict={1:a,2:b} 2 >>> dict 3 {1: a, 2: b} 4 >>> dict[3]={1: a} 5 >>> dict 6 {1: a, 2: b, 3: {1: a}} 7 >>> dict[3].update({2: b}); 8 >>> dict 9 {1: a, 2: b, 3: {1: a, 2: b}}10 >>> 

上面分为2个步骤;

下来访问嵌套字典:

1 >>> dict[3][1]2 a3 >>> dict[3][2]4 b5 >>> dict[1]6 a7 >>> dict[2]8 b9 >>> 

Python中字典嵌套??