Python Phonebook Lookup
dict.getPractice

Build a dict, then look up a name

Pairs on the second line become keys and values. Then book.get(name) returns the number.

Picture this: name to number

Fill the dictionary, then look up one key.

pairsname number
→
book[name]store
→
get(name)lookup

In easy words

A phonebook is a dictionary: names are keys, numbers are values. Lookup is O(1) instead of scanning a list.

Where this is used

Contacts apps, username-to-id maps, and config tables.

Run algorithm

Each step highlights the matching Python line. Program output appears only when a line that prints actually runs.

Ready
1name = input()
2pairs = input().split()
3book = {pairs[i]: pairs[i+1] for i in range(0, len(pairs), 2)}
4print(book.get(name, "Not found"))
Output:

Example Program

1name = input()
2pairs = input().split()
3book = {pairs[i]: pairs[i+1] for i in range(0, len(pairs), 2)}
4print(book.get(name, "Not found"))