需要迭代嵌套字典中的列表值
d = { 'a' :{'a': '3','b': '2 '},'b':{'c':'1'}}
temp = (20,31,111,455,55,6)
for i in d:
for j in d[i]:
for k in temp:
d[i][j]=k
print d
我希望以下几点:
d = { 'a' :{'a': '20','b': '31 '},'b':{'c':'111'}}
答案 0 :(得分:0)
尝试一下:
d = { 'a' :{'a': '3','b': '2 '},'b':{'c':'1'}}
temp = (20,31,111,455,55,6)
count=0
for i in d:
for j in d[i]:
#update nested dictionary value
d[i][j]=temp[count]
#increment count variable
count+=1
print(d)
O / P:
{'a': {'a': 20, 'b': 31}, 'b': {'c': 111}}