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.
Day 8: Dictionaries and Maps
Day 8: Dictionaries and Maps
Sort by
recency
|
2703 Discussions
|
Please Login in order to post a comment
I am facing a runtime issue in test case 1 in the following code (most probably due to time limit)
How to tackle this, is there any better way to do this in python.
`
""" 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
n = int(input())
phone_book = {}
for _ in range(n): entry = input().split() name = entry[0] phone_number = entry[1] phone_book[name] = phone_number
try: while True: query = input().strip() if query in phone_book: print(f"{query}={phone_book[query]}") else: print("Not found") except EOFError: pass
Im new in c++, and met a problem in test case 1, and I don't know where the problem is. Does anyone know the problem? Here's the code: