Combine Lists with Zip
You are given two lists and need to combine them into one dictionary.
The first list supplies the keys, and the second list supplies the values. That means the output is not a list of tuples here, even though zip() itself naturally creates paired tuples. The actual goal is to turn those pairs into a dictionary.
For example, if keys = ["name", "age"] and values = ["Alice", 25], the result should be {"name": "Alice", "age": 25}. If keys = [1, 2, 3] and values = ["one", "two", "three"], the result should be {1: "one", 2: "two", 3: "three"}. If both lists are empty, the answer is simply an empty dictionary.
So the task is to pair each key with the value in the same position and return the resulting mapping.
Example Input & Output
The first list provides keys and the second list provides their matching values.
Parallel lists are zipped together and turned into a dictionary.
Two empty input lists produce an empty dictionary.
Algorithm Flow

Solution Approach
This problem is meant to teach the practical use of Python's zip() function. The core idea of zip() is simple: it walks through multiple iterables in parallel and groups together the elements at matching positions.
If we have keys = ["name", "age"] and values = ["Alice", 25], then zip(keys, values) conceptually produces pairs like ("name", "Alice") and ("age", 25). Once we have those pairs, turning them into a dictionary is straightforward.
The cleanest Python solution is:
This is short, but it still has real structure. zip(keys, values) creates the aligned key-value pairs, and dict(...) consumes those pairs to build the final mapping.
One useful detail is how zip() behaves when the lists are different lengths. It stops at the shorter input. So if one list is longer, the extra items are ignored. In many problems that behavior is helpful, although here the tests suggest the inputs are meant to line up normally.
You could also solve this with a loop by iterating over zip(keys, values) and assigning into a dictionary one pair at a time. That works too, but dict(zip(...)) is the most direct expression of the idea. It keeps the pairing step and the dictionary-building step together, which makes the code easy to read.
Another nice point is readability of intent. If someone sees dict(zip(keys, values)), they can immediately understand that the two input lists are meant to be treated as parallel data. That is often better than indexing manually with range(len(keys)), which is more verbose and easier to get wrong.
The runtime is O(n) for n paired elements, and the extra space is O(n) for the resulting dictionary. The key lesson is that zip() is not just for creating tuples. It is often the cleanest bridge from two parallel lists into one combined structure.
Best Answers
def combine_lists(keys, values):
# Approach 1: Extremely Pythonic dict() casting paired with zip()
return dict(zip(keys, values))Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
