I need to create a phone directory with given inputs, then I need to query the dictionary for unknown number of given keys, if not found, print Not found. Link of Original HackerRank Problem here
I have written this code in Python3, and it's working fine. Please review, and suggest other ways of taking unknown number of inputs. Should it be done without using sys
?
import sys
phone={}
n = int(input())
for _ in range(n):
line = input().split()
phone[line[0]] = line[1]
for line in sys.stdin:
key=line.strip('\n')
try:
print(key+'='+phone[key])
except KeyError:
print('Not found')