You can use list comprehension like
print [key for key in d if d[key] == 1]
It iterates through the keys of the dictionary and checks if it matters 1. If the value is 1, it adds the corresponding list to the list.
Alternatively, you can use dict.iteritems()in Python 2.7, for example
print [key for key, value in d.iteritems() if value == 1]
In Python 3.x, you would do the same with dict.items(),
print([key for key, value in d.items() if value == 1])
source
share