def GetListOfKeysForGivenValueInDict(dictionary,value):
keys = []
for k,v in dictionary.items():
if v == value:
keys.append(k)
return keys
usage:
dictionary = {1:2,3:4,5:4}
value = 4
keys_list = GetListOfKeysForGivenValueInDict(dictionary, value)
print keys_list
result:
[3,5]
No comments:
Post a Comment