딕셔너리 자료구조를 사용하여 간단히 해결할 수 있는 문제이다.
저장되지 않은 Key를 입력받았을 경우 KeyError가 발생하기 때문에
예외처리를 해준다.
import sys
N,M = map(int, sys.stdin.readline().strip().split())
address_password = {}
i = 0
while i < N:
address, password = map(str, sys.stdin.readline().strip().split())
address_password[address] = password
i += 1
j = 0
while j < M:
address = sys.stdin.readline().strip()
try:
print(address_password[address])
except KeyError:
continue
j += 1