【发布时间】:2020-10-05 16:52:34
【问题描述】:
我有两本词典:
v = {'name': ['Peter', 'Paul', 'Mary'], 'city': ['London', 'Rome', 'NY'], 'country': ['GB', 'I', 'USA'], 'age': ['30', '35', '45']}
d = {'city': 'Rome', 'country': 'I', 'age': 35}
如果我在 v 中搜索来自 d 的确切值,我希望返回 Paul。
我是否必须通过所有可能性“嵌套循环”,或者是否有类似的简单方法
if all of d anywhere in v.rows:
print(v[name])
【问题讨论】:
-
你为什么使用列表字典而不是字典列表?
-
您当前的数据结构不适合这种搜索。
标签: python dictionary search find