Like this:

Copykeys = ['a', 'b', 'c']
values = [1, 2, 3]
dictionary = dict(zip(keys, values))
print(dictionary) # {'a': 1, 'b': 2, 'c': 3}

Voila :-) The pairwise dict constructor and zip function are awesomely useful.

Answer from Dan Lenski on Stack Overflow
Top answer
1 of 16
3000

Like this:

Copykeys = ['a', 'b', 'c']
values = [1, 2, 3]
dictionary = dict(zip(keys, values))
print(dictionary) # {'a': 1, 'b': 2, 'c': 3}

Voila :-) The pairwise dict constructor and zip function are awesomely useful.

2 of 16
251

Imagine that you have:

Copykeys = ('name', 'age', 'food')
values = ('Monty', 42, 'spam')

What is the simplest way to produce the following dictionary ?

Copydict = {'name' : 'Monty', 'age' : 42, 'food' : 'spam'}

Most performant, dict constructor with zip

Copynew_dict = dict(zip(keys, values))

In Python 3, zip now returns a lazy iterator, and this is now the most performant approach.

dict(zip(keys, values)) does require the one-time global lookup each for dict and zip, but it doesn't form any unnecessary intermediate data-structures or have to deal with local lookups in function application.

Runner-up, dict comprehension:

A close runner-up to using the dict constructor is to use the native syntax of a dict comprehension (not a list comprehension, as others have mistakenly put it):

Copynew_dict = {k: v for k, v in zip(keys, values)}

Choose this when you need to map or filter based on the keys or value.

In Python 2, zip returns a list, to avoid creating an unnecessary list, use izip instead (aliased to zip can reduce code changes when you move to Python 3).

Copyfrom itertools import izip as zip

So that is still (2.7):

Copynew_dict = {k: v for k, v in zip(keys, values)}

Python 2, ideal for <= 2.6

izip from itertools becomes zip in Python 3. izip is better than zip for Python 2 (because it avoids the unnecessary list creation), and ideal for 2.6 or below:

Copyfrom itertools import izip
new_dict = dict(izip(keys, values))

Result for all cases:

In all cases:

Copy>>> new_dict
{'age': 42, 'name': 'Monty', 'food': 'spam'}

Explanation:

If we look at the help on dict we see that it takes a variety of forms of arguments:


>>> help(dict)

class dict(object)
 |  dict() -> new empty dictionary
 |  dict(mapping) -> new dictionary initialized from a mapping object's
 |      (key, value) pairs
 |  dict(iterable) -> new dictionary initialized as if via:
 |      d = {}
 |      for k, v in iterable:
 |          d[k] = v
 |  dict(**kwargs) -> new dictionary initialized with the name=value pairs
 |      in the keyword argument list.  For example:  dict(one=1, two=2)

The optimal approach is to use an iterable while avoiding creating unnecessary data structures. In Python 2, zip creates an unnecessary list:

Copy>>> zip(keys, values)
[('name', 'Monty'), ('age', 42), ('food', 'spam')]

In Python 3, the equivalent would be:

Copy>>> list(zip(keys, values))
[('name', 'Monty'), ('age', 42), ('food', 'spam')]

and Python 3's zip merely creates an iterable object:

Copy>>> zip(keys, values)
<zip object at 0x7f0e2ad029c8>

Since we want to avoid creating unnecessary data structures, we usually want to avoid Python 2's zip (since it creates an unnecessary list).

Less performant alternatives:

This is a generator expression being passed to the dict constructor:

Copygenerator_expression = ((k, v) for k, v in zip(keys, values))
dict(generator_expression)

or equivalently:

Copydict((k, v) for k, v in zip(keys, values))

And this is a list comprehension being passed to the dict constructor:

Copydict([(k, v) for k, v in zip(keys, values)])

In the first two cases, an extra layer of non-operative (thus unnecessary) computation is placed over the zip iterable, and in the case of the list comprehension, an extra list is unnecessarily created. I would expect all of them to be less performant, and certainly not more-so.

Performance review:

In 64 bit Python 3.8.2 provided by Nix, on Ubuntu 16.04, ordered from fastest to slowest:

Copy>>> min(timeit.repeat(lambda: dict(zip(keys, values))))
0.6695233230129816
>>> min(timeit.repeat(lambda: {k: v for k, v in zip(keys, values)}))
0.6941362579818815
>>> min(timeit.repeat(lambda: {keys[i]: values[i] for i in range(len(keys))}))
0.8782548159942962
>>> 
>>> min(timeit.repeat(lambda: dict([(k, v) for k, v in zip(keys, values)])))
1.077607496001292
>>> min(timeit.repeat(lambda: dict((k, v) for k, v in zip(keys, values))))
1.1840861019445583

dict(zip(keys, values)) wins even with small sets of keys and values, but for larger sets, the differences in performance will become greater.

A commenter said:

min seems like a bad way to compare performance. Surely mean and/or max would be much more useful indicators for real usage.

We use min because these algorithms are deterministic. We want to know the performance of the algorithms under the best conditions possible.

If the operating system hangs for any reason, it has nothing to do with what we're trying to compare, so we need to exclude those kinds of results from our analysis.

If we used mean, those kinds of events would skew our results greatly, and if we used max we will only get the most extreme result - the one most likely affected by such an event.

A commenter also says:

In python 3.6.8, using mean values, the dict comprehension is indeed still faster, by about 30% for these small lists. For larger lists (10k random numbers), the dict call is about 10% faster.

I presume we mean dict(zip(... with 10k random numbers. That does sound like a fairly unusual use case. It does makes sense that the most direct calls would dominate in large datasets, and I wouldn't be surprised if OS hangs are dominating given how long it would take to run that test, further skewing your numbers. And if you use mean or max I would consider your results meaningless.

Let's use a more realistic size on our top examples:

Copyimport numpy
import timeit
l1 = list(numpy.random.random(100))
l2 = list(numpy.random.random(100))

And we see here that dict(zip(... does indeed run faster for larger datasets by about 20%.

Copy>>> min(timeit.repeat(lambda: {k: v for k, v in zip(l1, l2)}))
9.698965263989521
>>> min(timeit.repeat(lambda: dict(zip(l1, l2))))
7.9965161079890095
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-create-dictionary-from-the-list
Create Dictionary from the List-Python - GeeksforGeeks
July 15, 2025 - Explanation: dictionary comprehension create a dictionary by iterating over a. Each element ele becomes a key-value pair, where the key is formed by concatenating k ("def_key_") with ele using f-string formatting and the value remains ele.
Discussions

How to turn a list of lists into a dictionary where the first item of each sublist is used as key?
We can use tuple assignment with packing inside a dictionary comprehension, eg. data = [['James', '100.00', '90.00', '85.50'], ['Nick', '78.00', '85.00', '80.50'], ['William', '95.50', '92.00', '100.00']] data_dict = {name: values for name, *values in data} More on reddit.com
๐ŸŒ r/learnpython
5
4
November 28, 2022
Seeking to populate a dictionary from a series of lists
I am seeking to populate a new dictionary from a series of lists. These separate lists contain information to specific categories like employee name, employee wage, employee ID number, etc. I have previously used โ€œappendโ€ to add to lists, but I believe that this dictionary needs to be in ... More on discuss.python.org
๐ŸŒ discuss.python.org
19
0
September 7, 2022
how to know when to use Lists and when to Use dictionaries?

This is a complex question because there are times when either a dictionary, list, or tuple will work; and there are times where only one or two would work.

Dict

A dict does not* maintain order. Think of it like a literal dictionary: if I want to know the value of something, I just have to know its key. It's location inside the dict is completely irrelevant as long as I know the key. This makes it great for retrieving things that you can give a logical name to and updating things that you can give a logical name to. It's extremely fast for looking up the value of something. similar to a real dictionary, you have a good idea of where to start "searching" in an actual dictionary to find a word and don't have to flip through each and every page of the dictionary to find what you're looking for.

List

A list maintains order. If I load values into a list, they're always guaranteed to be in that order forever unless I explicitly change it. This isn't the case with dicts*. This allows you to do things like sort and order data in meaningful ways. A draw back with a list is that finding out if a value exists in a list could take a very long time if the items are unordered.

If I have an unordered list like this:

[['Hannah', 'black'], ['Mark', 'brown'], ['Avery', 'blonde'],....]

And I want to lookup the hair color of 'Peter', I have to search through every single value in the list to see if it matches Peter. If 'Peter' doesn't exist in the list, I will have gone through every value in the list. If the list of thousands of names long, this will take thousands of operations. However, if I had a dict mapping name to hair color, looking up if Peter exists in the dict would take roughly 1 operation, even if the dict was millions of mappings long.

Tuple

Tuples a bit like immutable lists. Meaning they hold values, and maintain order, but once you create one, you can never modify/add/or delete any of its values. A good use case of a tuple are related data that comes in fixed sizes and the order has a specific meaning:

# rgb color values
rgb = (255, 120, 30)

# x, y coordinates
coordinate = (-1, 0)

Tuples are also great for what I think of as "throw-away-lists". A list that you only use once, that will never grow, shrink, or change values can probably be turned into a tuple.

for name in ['Bob', 'Peter', 'Sarah']:
    print(name)


for name in ('Bob', 'Peter', 'Sarah'):
    print(name)

In the example above, both have the exact same output, although you will see people use either one. The list of names is never growing, shrinking, or changing value, so it can be converted to a tuple and probably should be converted to a tuple because a tuple is more efficient than a list.

-------------------------------------------------------------

In your example both dicts and lists would work, so why did the Automate The Boarding Stuff book use a dict for the Tic Tac Toe board instead of a list? (1) Probably because dict is a little harder to grasp so it would be good practice for the reader to get more exposure to using a dict. (2) If we did the list implementation, you would have to put the board in some type of order. Like this:

['', 'X', 'O', '', 'X', '', 'X', 'O', 'O']

One problem with the list implementation is that it is not obvious which index corresponds to which square on a Tic Tac Toe board. Are the first 3 indexes representing the top row? Or do they represent the left column? There's no way to really telling from the code alone. With the dict implementation, it's extremely obvious which value corresponds to which square on a Tic Tac Toe board.

But in this case, yes either a list or dict would work. A tuple would probably not be a great idea because it's immutable, and you can't update the values it holds without creating a brand new tuple.

-------------------------------------------------------------

* later version of Python does maintain dict entry order

More on reddit.com
๐ŸŒ r/learnpython
5
2
December 19, 2021
How to create a nested dictionary taking the keys from a list?
you can loop through the items of a list, right? You can use the variable of the loop and initialize an entry in the dictionary for every value seen: somekeys = ["dog", "cat", "bee", "dog"] mydict = {} for key in somekeys: mydict.setdefault(key, {'equation': None, 'direction': None}) print(mydict) Output: >> {'dog':ย {'equation':ย None,ย 'direction':ย None},ย 'cat':ย {'equation':ย None,ย 'direction':ย None},ย 'bee':ย {'equation':ย None,ย 'direction':ย None}} More on reddit.com
๐ŸŒ r/learnpython
10
9
October 18, 2018
๐ŸŒ
PythonHow
pythonhow.com โ€บ how โ€บ create-a-dictionary-with-list-comprehension
Here is how to create a dictionary with list comprehension in Python
In this example, we created a dictionary where the keys are the elements from the my_list and the values are the lengths of the corresponding elements.
๐ŸŒ
Medium
medium.com โ€บ @atatus โ€บ https-www-atatus-com-blog-python-converting-lsts-to-dictionaries-c3f038a8ce30
Python: Converting Lists to Dictionaries | by Atatus | Medium
September 16, 2024 - In the above code, we use the range() function to generate a sequence of integers from 0 to the length of the list my_list and then use the zip() function to create a list of tuples that incorporates both value and index of every individual element in the list. Finally, we convert this list of tuples to a dictionary using the dict() function, make dict from list python.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Seeking to populate a dictionary from a series of lists - Python Help - Discussions on Python.org
September 7, 2022 - I am seeking to populate a new dictionary from a series of lists. These separate lists contain information to specific categories like employee name, employee wage, employee ID number, etc. I have previously used โ€œappendโ€ to add to lists, but I believe that this dictionary needs to be in ...
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-convert-a-list-to-dictionary
Convert a List to Dictionary Python - GeeksforGeeks
Grouping elements into key-value pairs involves pairing consecutive elements in a list where the first becomes key and next becomes the value. ... a = ["a", 1, "b", 2, "c", 3] # Create dictionary by pairing elements, using every second element ...
Published ย  July 12, 2025
๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ convert-list-to-dictionary-python
10 Ways to Convert Lists to Dictionaries in Python | Built In
We can convert to a dictionary using the dict() constructor. As an example: from collections import ChainMap l1 = [{1:'a', 2:'b'}, {3:'c', 4:'d'}] d = dict(ChainMap(*l1)) print(d) #Output: {3: 'c', 4: 'd', 1: 'a', 2: 'b'}
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ dictionary-dict-function
Python Dictionary: Syntax and Examples [Python Tutorial]
In Python, you can create dictionaries with default values for all keys, which is useful when you need data structures with predictable defaults. You can use the built-in function fromkeys() to create a new dictionary where each key from a collection (e.g., a list) gets the same default value.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-convert-a-list-into-a-dictionary-with-index-as-key
Python program to Convert a list into a dictionary with index as key - GeeksforGeeks
July 23, 2025 - enumerate() function allows us to get both the index and value from the list simultaneously and makes this a simple and efficient way to create a dictionary where the index is the key.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-convert-a-list-of-tuples-into-dictionary
Convert a List of Tuples into Dictionary - Python - GeeksforGeeks
October 29, 2025 - dict() function converts an iterable of key-value pairs, such as a list of tuples, into a dictionary. It assigns the first element of each tuple as the key and the second as the corresponding value.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-create-list-of-dictionary-in-python
How to create list of dictionary in Python - GeeksforGeeks
July 23, 2025 - List comprehension is a compact way to create lists. We can use it to create a list of dictionaries in just one line.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ ways-to-create-a-dictionary-of-lists-in-python
Ways to create a dictionary of lists in python
March 27, 2026 - Create an empty dictionary and assign lists as values to string keys ? student_data = {} student_data["Names"] = ["RAM", "RAVI", "TARUN", "MOHAN"] student_data["Ages"] = [22, 23, 18, 27] print(student_data) {'Names': ['RAM', 'RAVI', 'TARUN', 'MOHAN'], 'Ages': [22, 23, 18, 27]} The defaultdict automatically creates missing keys with default list values ? from collections import defaultdict data_pairs = [("Name", "Arjun"), ("Age", 22), ("Age", 23), ("Age", 28), ("Name", "RAVI"), ("Name", "ADITYA")] grouped_data = defaultdict(list) for key, value in data_pairs: grouped_data[key].append(value) print(dict(grouped_data))
๐ŸŒ
w3resource
w3resource.com โ€บ python-exercises โ€บ dictionary โ€บ python-data-type-dictionary-exercise-63.php
Python: Convert a given list of lists to a dictionary - w3resource
June 28, 2025 - Write a Python program to convert a given list of lists to a dictionary. ... # Define a function 'test' that takes a list of lists 'lst' as an argument. def test(lst): # Use a dictionary comprehension to convert each list in 'lst' into a dictionary, # where the first element is the key, and the rest of the elements are values. result = {item[0]: item[1:] for item in lst} return result # Create a list of lists 'students' where each inner list represents student information.
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-create-a-dictionary-from-a-list-and-a-function-in-python-398164
How to create a dictionary from a list and a function in Python | LabEx
Python's versatile dictionary data structure is a powerful tool for organizing and manipulating data. In this tutorial, you will learn how to create a dictionary from a list and a function, unlocking new possibilities for efficient data management and processing in your Python projects.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-convert-two-lists-into-a-dictionary
Convert Two Lists into a Dictionary - Python - GeeksforGeeks
July 11, 2025 - Use zip to pair elements from two lists, where the first list provides the keys and second provides the values after that we convert the zipped object into a dictionary using dict() which creates key-value pairs.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ python-create-dictionary-from-the-list
Python โ€“ Create dictionary from the list
the_keys = {'b', 'c', 'd', 'f', 'g' } # the list value = [5] consonants = dict.fromkeys(the_keys, value) print('The consonants are: ', consonants) # updating the value of the list value.append(10) print('The updated dictionary is: ',consonants) ... The consonants are: {'c': [5], 'b': [5], 'f': [5], 'g': [5], 'd': [5]} The updated dictionary is: {'c': [5, 10], 'b': [5, 10], 'f': [5, 10], 'g': [5, 10], 'd': [5, 10]} In the following example a dictionary is created where a string is used as a key parameter.
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ convert list to dictionary in python: simple methods to know
Convert List to Dictionary in Python: Simple Methods to Know - AskPython
May 15, 2023 - The zip() function can take two or more lists as arguments and returns an iterator that contains tuples having the i-th element from each list. Then we can further convert those tuples to a dictionary using the dict() method. Letโ€™s now see an example that uses the Python zip() function to convert a list to a Python dictionary.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-pair-lists-elements-to-dictionary
Python - Pair lists elements to Dictionary - GeeksforGeeks
June 1, 2023 - Use dictionary comprehension to create a new dictionary, where each key is a unique element from test_list1, and the value is a list of all corresponding elements from test_list2.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-convert-list-to-list-of-dictionaries
Python - Convert List to List of dictionaries - GeeksforGeeks
July 15, 2025 - zip(a, values) pairs keys from a with corresponding values from each sublist in b, creating key-value pairs. List comprehension converts each paired sublist into a dictionary using dict() and collects all dictionaries into a list.