Day 8: Dictionaries and Maps

  • Instructions:
    • Given n names and phone numbers, assemble a phone book that maps friends’ names to their respective phone numbers.
    • Given an unknown number of names to query, print the associated entry from the phone book on a new line in the form name=phoneNumber
    • If an entry for name is not found, print Not found
    • Phone book should be a Dictionary/Map/HashMap data structure
    • Constraints:
      • 1 <= n <= 10^5
      • 1 <= queries <= 10^5
    Excercise
    1
    
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    
    Solution
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    
    #!/bin/python3
    # Enter your code here. Read input from STDIN. Print output to STDOUT
    
    if __name__ == '__main__':
        n = int(input())
        
        phoneBook=dict(input().split(' ',2) for _ in range(n))
        
        while True:
            try:
                name = str(input())
                if name in phoneBook.keys():
                    print("{}={}".format(name,phoneBook[name]))
                else:
                    print("Not found")
            except:
                break