您可以这样做:
#Just an example how the dictionary may look likemyDict = {'age': ['12'], 'address': ['34 Main Street, 212 First Avenue'], 'firstName': ['Alan', 'Mary-Ann'], 'lastName': ['Stone', 'Lee']}def search(values, searchFor): for k in values: for v in values[k]: if searchFor in v: return k return None#Checking if string 'Mary' exists in dictionary valueprint search(myDict, 'Mary') #prints firstName
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)