Python中的逆字典查找 [英] Inverse dictionary lookup in Python

查看:112
本文介绍了Python中的逆字典查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



所有我想到的都是这样的:

  key = [key for key,value_obj.items()中的值if value =='value'] [0] 


解决方案

没有。不要忘记,可以在任意数量的键上找到该值,包括0或超过1个。


Is there any straightforward way of finding a key by knowing the value within a dictionary?

All I can think of is this:

key = [key for key, value in dict_obj.items() if value == 'value'][0]

解决方案

There is none. Don't forget that the value may be found on any number of keys, including 0 or more than 1.

这篇关于Python中的逆字典查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆