Python, how to get the corresponding key value according to the value value in the dictionary

  python

For example:
dicxx = {‘a’:’001′, ‘b’:’002′}

You need to get a according to input 001.

What if? Baidu spent half a day without finding the answer. Thank you

To help you search,

>>> dicxx = {'a':'001', 'b':'002'}
 >>> list(dicxx.keys())[list(dicxx.values()).index("001")]
 'a'
 >>>

To quote from a Python3 document.

If keys, values and items views are iterated over with no intervening modifications to the dictionary, the order of items will directly correspond.

In other words, if no dictionary changes have taken place during your iteration, the dict-view objects returned by the. keys() and .values functions will always maintain the corresponding relationship.