Start
##The Fromkeys method itself is to point all keys to the same object.>>> C=dict.fromkeys (Range (5), [])
>>> c{0: [], 1: [], 2: [], 3: [], 4: []}>>> c[0].append ({"B": {123}}) >>> c{0: [{' B ': Set ([123])} ], 1: [{' B ': Set ([123]}], 2: [{' B ': Set ([123])}], 3: [{' B ': Set ([123])}], 4: [{' B ': Set ([123])}]}>>> C[0].append (1) >>> c{0: [{' B ': Set ([123]}, 1], 1: [{' B ': Set ([123])}, 1], 2: [{' B ': Set ([123])}, 1], 3: [{' B ': set ([123])}, 1], 4: [{' B ': Set ([123])}, 1]}
# #怎么解决我只想修改c [0] What's the value inside? FIX: Point to another list object first
>>> C=c.fromkeys (Range (5), []) >>> c{0: [], 1: [], 2: [], 3: [], 4: []}>>> c[ 0]=[]>>> C[0].append ({"B": {123}}) >>> c{0: [{' B ': Set ([123])}], 1: [], 2: [], 3: [], 4: []}>>> C[0].append (1) >>> c{0: [{' B ': Set ([123])}, 1], 1: [], 2: [], 3: [], 4: []}>>>
# #直接定义字典 >>> b={0: [], 1: [], 2: [], 3: [], 4: []}>>> b[0].append ({"B": {123}}) >>> b{0: [{' B ': SE T ([123])}], 1: [], 2: [], 3: [], 4: []}>>> b[0].append (1)>>> b{0: [{' B ': Set ([123])}, 1], 1: [], 2: [], 3: [], 4: []}
# #不用fromkeys生成一个大字典的办法 >>> c={}>>> c{}>>> for I in range (5): ... c[i]=[] ... >>> c{0: [], 1: [], 2: [], 3: [], 4: []}end
From for notes (Wiz)
Day②: The Fromkeys method of the dictionary