获取键对应于字典中的值 [英] get keys correspond to a value in dictionary
本文介绍了获取键对应于字典中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在python中有这个字典
I have this dictionary in python
d={1: 'a', 2: 'b', 3: 'c'}
带有d [1]我得到
>>> d[1]
'a'
我如何获得对应于值的键?
示例:使用'a'得到1
how I can get the key correspond to a value ?
example : with 'a' get 1
推荐答案
您想要反转映射:
如此问题所示
dict((v,k) for k, v in map.iteritems())
这篇关于获取键对应于字典中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文