这是我定义的函数
def find_key_of_value(d: dict, val):
if val in d.values():
key = list(d.keys())[list(d.values()).index(val)]
return key
else:
return None
然后调用
print(find_key_of_value({'a':a, 'b':b, 'c':c},b))
如果值是数字,都没有问题,但是改成了字母,就会报错了
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-54-571009abf18d> in <module>
----> 1 print(find_key_of_value({'a':a, 'b':b, 'c':c},b))
NameError: name 'b' is not defined
初来乍到还没有c币,请大神体谅