从嵌套字典调用特定键/值的Python方式

从嵌套字典调用特定键/值的Python方式,python,dictionary,Python,Dictionary,从嵌套字典中获取特定键/值的Python方式是什么 例如,我想从这个嵌套字典中获取所有奇数dict值: nested_dict = {'bulldog': {'type': 3}, 'cat': {'type': 4}, 'yorkie': {'type': 11}, 'pitbull': {'type': 8}} 输出应如下所示: new_dict = {'bulldog': {'type': 3}, 'yorkie': {'type': 11}} new_dict2 = {'type':

从嵌套字典中获取特定键/值的Python方式是什么

例如,我想从这个嵌套字典中获取所有奇数dict值:

nested_dict = {'bulldog': {'type': 3}, 'cat': {'type': 4}, 'yorkie': {'type': 11}, 'pitbull': {'type': 8}}
输出应如下所示:

new_dict = {'bulldog': {'type': 3}, 'yorkie': {'type': 11}}
new_dict2 = {'type': 3, 'type': 11}
此外,如果我只想拉取具有奇数值的嵌套键,在这种情况下,输出将如下所示:

new_dict = {'bulldog': {'type': 3}, 'yorkie': {'type': 11}}
new_dict2 = {'type': 3, 'type': 11}

这是相当直接的使用类似的:

代码: 测试代码: 结果:
new_dict2
有重复的钥匙……谢谢你,这正是我要找的!我试图使用dict理解,但无法让它与嵌套字典一起正常工作。这非常有用。
{'bulldog': {'type': 3}, 'yorkie': {'type': 11}}