It is straight-forward to extract value if we have key, like unlocking a lock with a key. However, the vice versa is not as simple, like “unkeying the key with a lock”, maybe!

Sometimes extracting keys become important especially when the key and value has a one-to-one relationship. That is, when either of them is unique and hence can act as the key.

Before getting into the various methods, first we will create a dictionary for the purpose of illustration.

currency_dict is the dictionary with currency abbreviations as keys and currency names as value.

currency_dict={'USD':'Dollar',
             'EUR':'Euro',
             'GBP':'Pound',
              'INR':'Rupee'}

If you have the key, getting the value by simply adding the key within square brackets.

For example, currency_dict[‘GBP’] will return ‘Pound’.

#dictionary #data-science #python #how-to #coding

How to Extract Key from Python Dictionary using Value
1.85 GEEK