How can you print a key given a value in a dictionary for Python?

dictionary, key, python

Solution

I don't believe there is a way to do it. It's not how a dictionary is intended to be used... Instead, you'll have to do something similar to this.

for key, value in dictionary.items():
    if 4 == value:
        print key

Problem

For example lets say we have the following dictionary: ``` dictionary = {'A':4, 'B':6, 'C':-2, 'D':-8} ``` How can you print a certain key given its value? ``` print(dictionary.get('A')) #This will print 4 ``` How can you do it backwards? i.e. instead of getting a value by referencing the key, getting a key by referencing the value.

Original source

Related problems