【发布时间】:2013-11-04 06:57:48
【问题描述】:
我有一个 Python 字典,其中人的姓氏作为键,每个键都有多个链接到它的值。有没有办法使用 for 循环遍历字典以搜索特定值,然后返回该值链接到的键?
for i in people:
if people[i] == criteria: #people is the dictionary and criteria is just a string
print dictKey #dictKey is just whatever the key is that the criteria matched element is linked to
可能还有多个匹配项,所以我需要人们输出多个键。
【问题讨论】:
-
你看到
i是什么了吗?这是一把钥匙。 -
我不只是在寻找钥匙。我需要查看链接到每个键的数据,如果与搜索条件匹配,程序将返回找到匹配项的键。
标签: python dictionary