按值索引python字典

2024-04-20 07:38:20 发布

您现在位置:Python中文网/ 问答频道 /正文

Possible Duplicate:
Inverse dictionary lookup - Python

在Python中是否有一种内置的方法来按值索引字典。

比如说:

dict = {'fruit':'apple','colour':'blue','meat':'beef'}
print key where dict[key] == 'apple'

或:

dict = {'fruit':['apple', 'banana'], 'colour':'blue'}
print key where 'apple' in dict[key]

还是必须手动循环?


Tags: 方法keyappledictionarybluelookupwhere内置