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