Python Day 8: Dictionaries and Maps




Given n names and phone numbers, assemble a phone book that maps friends' names to their respective phone numbers. You will then be given an unknown number of names to query your phone book for. For each name queried, print the associated entry from your phone book on a new line in the form name=phoneNumber; if an entry for name is not found, print Not found instead.



  1. n = int(input())
  2. d = {}
  3. for i in range(n):
  4. x = input().split()
  5. d[x[0]] = x[1]
  6. while True:
  7. try:
  8. name = input()
  9. if name in d:
  10. print(name, "=", d[name], sep="")
  11. else : print("Not found")
  12. except: break




codesadda.com

Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube