我有字典:dict
defaultdict(<type 'list'>, {'network3_ICU_0001_01_(0, 1)': [(0.39, 'yes')], network3_ICU_0001_01_(0, 2)': [(0.79, 'yes'), 'network3_ICU_0001_01_(1, 2)': [(0.39, 'yes')]]}
defaultdict(<type 'list'>, {'network3_MCU_0032_02_(0, 1)': [(0.47, 'yes')], 'network3_MCU_0032_02_(0, 2)': [(0.55, 'yes')], 'network3_MCU_0032_02_(1, 2)': [(0.39, 'yes')]}
defaultdict(<type 'list'>, {'network3_CCA_0045_03_(0, 1)': [(0.43, 'no')], 'network3_CCA_0045_03_(0, 2)': [(0.53, 'no')], 'network3_CCA_0045_03_(1, 2)': [(0.99, 'no')]}
我想提取末尾包含(0,1)的子键值,因此结果如下所示:
{'network3_ICU_0001_01_(0, 1)': [(0.39, 'yes')]}
{'network3_MCU_0032_02_(0, 1)': [(0.47, 'yes')]}
{'network3_CCA_0045_03_(0, 1)': [(0.43, 'no')]}
然后我想将其移至新词典
到目前为止,我的代码如下:
return_values = {k:v for k,v in network3.items() if k.endswith('(0, 1)')}
print(return_values)
这段代码没有返回任何值,我想这可能是因为我在调用键而不是子键...我不确定如何执行此操作。
任何帮助将不胜感激:)