30 Days of Code — Day 8

Tyler Carter
2 min readMar 11, 2021
Photo by Shahadat Rahman on Unsplash

Welcome to day 8 of 30 Days of Code from Hacker Rank!

The Task

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 is not found, print Not found instead.

The Code

The Result

>? 3
>? sam 99912222
>? tom 11122222
>? harry 12299933
>? frederick
… Not found
>?xiao
… Not found
>? tom
… tom=11122222

Conclusion

I actually learned quite a bit on this one. First and foremost I did not know how to split an input. I had to look that up in order to implement. Additionally, I am not overly familiar with dictionary comprehension but I knew enough to get through this.

I also was thrown for a loop on setting something up for an infinite cycle. At first, I overcomplicate the solution by storing the input names in a list and having a condition while name =! "quit": to allow the user an escape. But it did not quite work as intended. I did have to look online for some help here but I am of the mind that it is fine to look for help.

Here is a link to the day_7 answer/challenge I wrote about previously: 30 Days of Code — Day 7.

--

--

Tyler Carter
0 Followers

I am currently an Operations Program Manager for Microsoft. I have been teaching myself Python to use for Data Analytics and Machine Learning.