Last modified: Nov 19, 2026

Python Zip Two Lists into a Dictionary

You often have two lists. One holds keys. The other holds values. You want to merge them into a single dictionary.

Python makes this easy. The built-in zip function pairs items from both lists. Then dict turns those pairs into a dictionary.

This guide shows the simple way, the safe way, and the common mistakes. It is written for beginners.

The Basic Idea

A dictionary needs key-value pairs. Two lists give you two sequences. You pair the first item of list A with the first item of list B. Then the second with the second, and so on.

That pairing is exactly what zip does. It stops when the shorter list runs out.

Here is the simplest example.


keys = ["name", "age", "city"]
values = ["Alice", 30, "Paris"]

# zip pairs items, dict converts the pairs into a dictionary
result = dict(zip(keys, values))
print(result)

{'name': 'Alice', 'age': 30, 'city': 'Paris'}

Two lines of code. That is all you need for most cases.

How zip Works Under the Hood

zip returns an iterator of tuples. Each tuple holds one item from each input list.

You can see the raw pairs before converting them.


keys = ["a", "b", "c"]
values = [1, 2, 3]

pairs = list(zip(keys, values))
print(pairs)

[('a', 1), ('b', 2), ('c', 3)]

If you want to go deeper into this function, read this guide on the Python zip function for combining iterables.

The iterator is lazy. It produces pairs one at a time. This keeps memory use low, even with large lists.

What Happens with Unequal Lengths

This is the most common surprise. zip stops at the shortest list. Extra items are silently dropped.


keys = ["a", "b", "c"]
values = [1, 2]

# "c" has no matching value, so it is dropped
result = dict(zip(keys, values))
print(result)

{'a': 1, 'b': 2}

No error is raised. That can hide bugs. If your lists should match in length, check first.


keys = ["a", "b", "c"]
values = [1, 2]

if len(keys) != len(values):
    print("Warning: lists have different lengths")

result = dict(zip(keys, values))
print(result)

Warning: lists have different lengths
{'a': 1, 'b': 2}

In Python 3.10 and later, you can use the strict option. It raises a ValueError when lengths differ.


keys = ["a", "b", "c"]
values = [1, 2]

# strict=True raises an error instead of silently dropping items
try:
    result = dict(zip(keys, values, strict=True))
except ValueError as e:
    print("Error:", e)

Error: zip() argument 2 is shorter than argument 1

Duplicate Keys

Keys in a dictionary must be unique. If the keys list has duplicates, the last value wins.


keys = ["a", "b", "a"]
values = [1, 2, 3]

# The second "a" overwrites the first
result = dict(zip(keys, values))
print(result)

{'a': 3, 'b': 2}

This is not an error. It is just how dictionaries work. Keep it in mind when your keys come from user input or messy data.

Using a Dictionary Comprehension

You can also build the dictionary with a comprehension. It gives you room to change keys or values on the fly.


keys = ["name", "age", "city"]
values = ["Alice", 30, "Paris"]

# Same result, but easier to transform values
result = {k: v for k, v in zip(keys, values)}
print(result)

{'name': 'Alice', 'age': 30, 'city': 'Paris'}

Now add a small change. For example, uppercase every key.


result = {k.upper(): v for k, v in zip(keys, values)}
print(result)

{'NAME': 'Alice', 'AGE': 30, 'CITY': 'Paris'}

If you like this style, the lambda function syntax guide shows how to pair it with small inline functions.

Zipping More Than Two Lists

zip accepts any number of lists. With three lists, each tuple has three items.


keys = ["a", "b"]
first = [1, 2]
second = [10, 20]

# Build a dict where each value is a tuple
result = dict(zip(keys, zip(first, second)))
print(result)

{'a': (1, 10), 'b': (2, 20)}

Real-World Example: Two Columns of Data

Imagine you read a CSV file and split it into two lists. One list holds product names. The other holds prices.


products = ["apple", "banana", "cherry"]
prices = [1.20, 0.50, 3.00]

# Build a price lookup table
price_map = dict(zip(products, prices))

for name in products:
    print(f"{name}: ${price_map[name]}")

apple: $1.2
banana: $0.5
cherry: $3.0

This pattern appears everywhere. It is fast and readable. It also avoids manual index loops.

Common Mistakes to Avoid

Assuming equal lengths. Always check or use strict=True when the data should match.

Passing a list of lists.dict needs pairs. Each inner list must have exactly two items.


# This works: each inner list has two items
pairs = [["a", 1], ["b", 2]]
print(dict(pairs))

# This fails: three items in a pair
bad = [["a", 1, 2]]
try:
    print(dict(bad))
except ValueError as e:
    print("Error:", e)

{'a': 1, 'b': 2}
Error: dictionary update sequence element #0 has length 3; 2 is required

Forgetting order. Keys and values must line up by position. A sort on one list alone will break the mapping.

If you need to inspect pairs while debugging, the Python enumerate complete guide shows how to loop with indexes safely.

Comparing Alternatives

You could write a manual loop. It works, but it is longer.


keys = ["a", "b"]
values = [1, 2]

result = {}
for i in range(len(keys)):
    result[keys[i]] = values[i]

print(result)

{'a': 1, 'b': 2}

The dict(zip(...)) version is shorter and less error-prone. Prefer it unless you need custom logic inside the loop.

Some developers use map to transform data before building the dictionary. That is fine, but for simple pairing, plain zip is clearer.

Performance Notes

zip is lazy and fast. It does not copy the input lists. dict then consumes the pairs once.

For large lists, this approach is efficient. Memory use grows with the dictionary size, not with extra copies of the lists.

The comprehension version is nearly as fast. Use it when you need to transform keys or values.

Quick Checklist

Use dict(zip(keys, values)) for the common case. Confirm both lists have the same length. Watch for duplicate keys. Use a comprehension when you need to modify items.

These steps cover almost every real-world situation you will meet.

Conclusion

Converting two lists into a dictionary in Python takes one line. The zip function pairs items, and dict builds the mapping.

Remember the key points. zip stops at the shortest list. Duplicate keys keep the last value. Use strict=True to catch length mismatches early.

Practice with small examples first. Then apply the pattern to real data like CSV columns or lookup tables. Once you know it, you will use it often.