-3

I want a function which will take value from user and display the respective key of the dictionary

Ex. d={'name':'ayush','age':21,'Hobby':'cricket'}

Please enter the value : ayush Key related to entered value is: name

1 Answers1

0

Here is one option with list-comprehension:

[k for k, v in d.items() if v == 'ayush']
# ['name']
Psidom
  • 209,562
  • 33
  • 339
  • 356