标签:ted port from 访问 you 词典 code ict pre
逐层访问词典,直到最后一层
from nested_dict import nested_dict
a = {"hi":{"you":{"dd": 3}}, "h":{"yo":{"d": 2}}}
for i in nested_dict(a).items_flat():
print(i)
输出
((‘hi‘, ‘you‘, ‘dd‘), 3)
((‘h‘, ‘yo‘, ‘d‘), 2)
b = {‘.‘.join(k): v for k, v in nested_dict(a).items_flat()}
print(b)
输出
{‘hi.you.dd‘: 3, ‘h.yo.d‘: 2}
标签:ted port from 访问 you 词典 code ict pre
原文地址:https://www.cnblogs.com/huanxifan/p/12627119.html