0

I created tuples as keys in dictionary and trying to run a search with user input.

directory = {('a','b'):1, ('c','d'):2, ('e','f'):3}
numsearch = input("enter number to search: ")

if numsearch in directory.values():
    print(directory.values())

or

print(directory.items())

does not throw any error or output a value.

Appreciate any help if you tell me the error in my code

X10nD
  • 21,638
  • 45
  • 111
  • 152

1 Answers1

3
directory = {('a','b'):1, ('c','d'):2, ('e','f'):3}
numsearch = input("enter number to search: ")

for k,v in directory.items():
    if int(numsearch) == v:
      print(k)
Fuji Komalan
  • 1,979
  • 16
  • 25