X10nD X10nD - 3 months ago 26
Python Question

Search in Directories with tuples as keys - python

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

Answer Source
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)