I have a dictionary of objects:
dic = {'k1':obj1, 'k2':obj2, 'k3':obj3, ...}
class MyObject:
def __init__(self,x,y):
self.x=x
self.y=y
I wonder how I can have the best implementation for finding the key that corresponds to a value. Something equivalent to:
def find_key(dic, val):
for k,v in dic.items():
if v==val:
return k
return None
NB: Sorry if this is obvious, I am a newbie in Python :-)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…