We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
"""
This is my submission in Python, it's not runnning within time limits, can someone help?
"""
import re
phoneBook = {}
if name == 'main':
n = int(input().strip())
for i in range(n):
match = re.match(r'(\w+)\s+(\d+)', input().strip())
phoneBook[match.group(1)] = match.group(2)
def queryPhoneBook(name):
if name in list(phoneBook.keys()):
print(f'{name}={phoneBook[name]}')
else:
print('Not found')
try:
go = True
while go:
q = input().strip()
if len(q)>0:
queryPhoneBook(q)
else:
break
except EOFError:
pass
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 8: Dictionaries and Maps
You are viewing a single comment's thread. Return to all comments →
""" This is my submission in Python, it's not runnning within time limits, can someone help? """
import re
phoneBook = {} if name == 'main': n = int(input().strip()) for i in range(n): match = re.match(r'(\w+)\s+(\d+)', input().strip()) phoneBook[match.group(1)] = match.group(2)
def queryPhoneBook(name): if name in list(phoneBook.keys()): print(f'{name}={phoneBook[name]}') else: print('Not found')
try: go = True while go: q = input().strip() if len(q)>0: queryPhoneBook(q) else: break except EOFError: pass