본문 바로가기

코드연습/Python

HackerRank | Day 8: Dictionaries and Maps

728x90

Key-Value pair mappings using a Map or Dictionary data structure

 

#Sample Input

3
sam 99912222
tom 11122222
harry 12299933
sam
edward
harry


#Sample Output

sam=99912222
Not found
harry=12299933

1. Dictionary(사전) 타입을 이용해서 key-value 쌍으로 구성된 데이터를 구축

2. 출력하는 문제이다.

n = int(input())

dict_list = {}
for i in range(n):
    name, num = input().split()
    dict_list[name] = num

while True:
	try:
      name = input()
      if name in dict_list:
          print(f"{name}={dict_list[name]}")
      else:
          print('Not found')
    except:
      break