Library Card Pairing with zip()
A school librarian has prepared two matching lists for a new student registration day. One list contains student names, and the second list contains the library card numbers that belong to those same students in the same order.
Your task is to turn those two lists into a single dictionary. Each student name should become a key, and the matching card number should become the value stored for that key.
For example, if the input lists are ["Ayu", "Bima", "Caca"] and ["LC101", "LC102", "LC103"], the result should be {"Ayu": "LC101", "Bima": "LC102", "Caca": "LC103"}. If both lists are empty, the result should be an empty dictionary.
You can assume the two input lists always have the same length. The main goal is to connect values from one list with the values at the same positions in the other list and return the final mapping.
Example Input & Output
Each student name is paired with the card number in the same position.
Two empty lists produce an empty directory.
A one-item pair of lists becomes a one-item dictionary.
Algorithm Flow

Solution Approach
This challenge is really about pairing two ordered lists together. The first element in names belongs with the first element in card_numbers, the second belongs with the second, and so on.
Python has a built-in tool that fits that idea perfectly: zip(). It walks through two sequences at the same time and produces pairs of matching values. Once those pairs exist, building the dictionary becomes very direct.
The shortest version is:
That line asks Python to pair every name with the card number at the same position, then convert the resulting pairs into a dictionary. It is compact, but the logic stays very readable because the input structure already matches what zip() expects.
If you prefer to see the steps more clearly, you can also loop through the paired values and assign them one by one:
Both versions do the same job. The important idea is that zip() keeps the two lists aligned without needing a manual index variable. That makes it a very natural Python solution for problems where two lists describe one shared set of records.
The runtime is O(n) because each pair is processed once, and the output dictionary stores one entry per student. For a beginner problem about moving from lists into dictionary data, this is a clean pattern to learn early.
Best Answers
def build_card_directory(names, card_numbers):
return dict(zip(names, card_numbers))Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
