Problem:- Write a Hackerrank Solution For Day 8: Dictionaries and Maps or Hacker Rank Solution Program In C++ For ” Day 8: Dictionaries and Maps ” or Hackerrank 30 days of code Java Solution: Day 8: Dictionaries and Maps solution or Hackerrank solution for 30 Days of Code Challenges or Hackerrank 30 days of code Java Solution: Day 8: Dictionaries and Maps, or C/C++ Logic & Problem Solving: Day 8: Dictionaries and Maps.
Logic:- Day 8: Dictionaries and Maps as we know that Dictionaries is a collection of data(variety of data). So for this problem, we can take an example of the phone book. Phonebook consists of various phone data line name, address and phone number, we are considering only phone name and number. We can solve this problem by considering a phone book. See the below explanation.
Dictionaries and Maps solution in Python :
n = int(input()) phonebook = dict() for i in range(n): line = input() line = line.split() phonebook[line] = phonebook.get(line,line) while 1: try: q = input() if q in phonebook: print(str(q) + "=" + str(phonebook[q])) else: print("Not found") except: break