1
我想剥离一个嵌套的字典(只有1级深度,例如:some_dict = {'a':{}, b:{}}
所有非零值和无值
但是,我不确定谁重新组装字典,下面给我一个关键的错误剥离非零值的嵌套字典
def strip_nested_dict(self, some_dict):
new_dict = {}
for sub_dict_key, sub_dict in some_dict.items():
for key, value in sub_dict.items():
if value:
new_dict[sub_dict_key][key] = value
return new_dict
请提供示例输入和所需输出 – wim