Looping over a dictionary only yields the keys. Use d.items() to loop over both keys and values:

{key: value for key, value in d.items()}

The ValueError exception you see is not a dict comprehension problem, nor is it limited to Python 3; you'd see the same problem in Python 2 or with a regular for loop:

>>> d = {'a':1, 'b':2, 'c':3, 'd':4}
>>> for key, value in d:
...     print key, value
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: need more than 1 value to unpack

because each iteration there is only one item being yielded.

Without a transformation, {k: v for k, v in d.items()} is just a verbose and costly d.copy(); use a dict comprehension only when you do a little more with the keys or values, or use conditions or a more complex loop construct.

Answer from Martijn Pieters on Stack Overflow
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ tutorial โ€บ datastructures.html
5. Data Structures โ€” Python 3.14.6 documentation
Similarly to list comprehensions, set comprehensions are also supported: >>> a = {x for x in 'abracadabra' if x not in 'abc'} >>> a {'r', 'd'} Another useful data type built into Python is the dictionary (see Mapping Types โ€” dict).
Discussions

How to create a dictionary with "list comprehension"?
You can't. Dictionaries can't have duplicate keys. That's one of the fundamental properties of dictionaries/maps. You're trying to have duplicate 0 keys, which isn't allowed. The opposite is allowed though: >>> { i:0 for i in range(3,6) } {3: 0, 4: 0, 5: 0} Also note, this is called a dictionary comprehension. More on reddit.com
๐ŸŒ r/learnpython
3
1
January 22, 2022
dictionary comprehension -- order of keys created?
What you are creating are sets, not dictionaries. And to the best of my knowledge, the python set container makes no guarantees regarding order. It may not even be the same on every run? There is such a thing as a dictionary comprehension though. For example, you could write: >>> {x: x * 2 for x in str(90210)} {'9': '99', '0': '00', '2': '22', '1': '11'} As of python 3.6 (I think?), the dict container does try to maintain the order in which items are inserted. More on reddit.com
๐ŸŒ r/learnpython
5
1
April 6, 2023
struggling with python 3 dict comprehension
I think an exception error msg ... but 3 were given` made me think that there's another immediate clue on what to fix inside the error message aside from 'too many values to unpack' ... Comprehensions on a dictionary default to iterating over its keys only. Change in d to in d.items() ... I'm not familiar with python 2, but judging ... More on reddit.com
๐ŸŒ r/learnpython
16
21
August 22, 2018
Dict unpacking in dict comprehensions
It is a bit noisy for what it does, and mildly confusing. I don't know a more idiomatic way. Stackoverflow is full of ** about it too. Leanest py3 oneliner I can come up with is this: merged = dict(i for i in d.items() for d in dict_list) More on reddit.com
๐ŸŒ r/Python
10
9
April 13, 2016
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-dictionary-comprehension
Python Dictionary Comprehension - GeeksforGeeks
April 18, 2026 - Dictionary comprehension is used to create a dictionary in a short and clear way. It allows keys and values to be generated from a loop in one line. This helps in building dictionaries directly without writing multiple statements.
๐ŸŒ
Switowski
switowski.com โ€บ blog โ€บ dictionary-comprehension
Dictionary Comprehension
January 19, 2023 - Compared with the old way of passing a list of tuples (in Python 2.6 and below), it's faster and more readable. But it only makes sense to use it when you compute a key or a value on the fly or if you want to do some filtering. If both the key and the value are ready (for example, they come from two different iterables), simply passing the zip() function to dict() results in a much faster and more readable code: # Good use case for dictionary comprehension - we compute the value {i: i * i for i in range(1000)} # Good use case for dictionary comprehension - we compute the key {i * i: i for i in
๐ŸŒ
Codecademy
codecademy.com โ€บ article โ€บ what-is-dictionary-comprehension-in-python
What Is Dictionary Comprehension in Python? | Codecademy
... Continue your Swift journey by learning these collection types: arrays, sets, and dictionaries! ... Dictionary comprehension is a feature in Python that allows us to build dictionaries in a single, elegant line of code.
๐ŸŒ
Python
peps.python.org โ€บ pep-0274
PEP 274 โ€“ Dict Comprehensions | peps.python.org
October 25, 2001 - You can use dict comprehensions in ways very similar to list comprehensions, except that they produce Python dictionary objects instead of list objects. This PEP was originally written for inclusion in Python 2.3.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-dictionary-comprehension
Python Dictionary Comprehension Tutorial | DataCamp
December 4, 2024 - The way to do dictionary comprehension in Python is to be able to access the key objects and the value objects of a dictionary. ... dict1 = {'a': 1, 'b': 2, 'c': 3, 'd': 4} # Put all keys of `dict1` in a list and returns the list dict1.keys()
Find elsewhere
๐ŸŒ
SitePoint
sitepoint.com โ€บ python hub โ€บ dictionary comprehension
Python - Dictionary Comprehension | SitePoint โ€” SitePoint
In this code snippet, we are creating a dictionary that maps each character in the word "PYTHON" to its position (index) in the word using a dictionary comprehension. ... We start with the string word containing "PYTHON". The enumerate function returns an iterator of tuples, where each tuple contains an index and the corresponding character from the string. For the string "PYTHON", enumerate(word) will produce: [(0, 'P'), (1, 'Y'), (2, 'T'), (3, 'H'), (4, 'O'), (5, 'N')]
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ dictionary-comprehension
Python Dictionary Comprehension: Syntax, Usage, and Examples
Create dictionaries fast with Python dictionary comprehension using {key: value for ...} syntax, letting you transform and filter key-value pairs and build lookup tables in a single readable line.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_dictionaries.asp
Python Dictionaries
A dictionary is a collection which is ordered*, changeable and do not allow duplicates. As of Python version 3.7, dictionaries are ordered.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ glossary.html
Glossary โ€” Python 3.14.6 documentation
dictionary comprehensionยถ ยท A compact way to process all or part of the elements in an iterable and return a dictionary with the results. results = {n: n ** 2 for n in range(10)} generates a dictionary containing key n mapped to value n ** ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ dictionary-comprehension-in-python-dict-comprehensions-explained
Dictionary Comprehension in Python โ€“ Dict Comprehensions Explained
September 16, 2022 - In the example above, we created a dictionary called developers which stores a list of developers with their favorite languages: {'Jane': 'Python', 'Jade': 'JavaScript', 'John': 'Python', 'Doe': 'JavaScript'}. In the dictionary comprehension, we added an expression at the end: if value == 'Python'.
๐ŸŒ
Tabnine
tabnine.com โ€บ home โ€บ the ultimate guide to python dictionary comprehension
The ultimate guide to Python Dictionary comprehension - Tabnine
July 25, 2024 - Overall, there are less lines involved with a dictionary comprehension and informs the developer exactly what the expected end result is to be โ€” another dictionary with the values translated and transformed from the original dictionary. This is the barebones basics of python dictionary comprehension.
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ dictionary-comprehension-python
Python Dictionary Comprehension: Syntax & Cases (with code)
March 6, 2023 - Let us look at a simple example to grasp the difference between a dictionary and dictionary comprehension: Consider a dictionary called Houses, the key expression is the house names (1-5) and the value expression is the house number. The house number is denoted by house name + area code (1110) this is how we would write the code : Houses = {1: 1111, 2: 1112, 3: 1113, 4: 1114, 5: 1115} print( houses)
๐ŸŒ
YouTube
youtube.com โ€บ watch
Python Dictionary Comprehensions - YouTube
Comprehensions are a powerful tool in Python that allow you to create new lists, sets and dictionaries, populated with values. This video explains how Dict c...
Published ย  May 9, 2023
๐ŸŒ
Javatpoint
javatpoint.com โ€บ dictionary-comprehension-in-python
Dictionary Comprehension in Python - Javatpoint
Dictionary Comprehension in Python with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, operators, etc.
๐ŸŒ
Alma Better
almabetter.com โ€บ bytes โ€บ tutorials โ€บ python โ€บ dictionary-comprehension-python
Dictionary Comprehension in Python
April 25, 2024 - Dictionary comprehension could be a Python feature that makes a new dictionary from an iterable object employing a brief syntax.
๐ŸŒ
Medium
medium.com โ€บ geekculture โ€บ list-comprehension-and-dictionary-comprehension-6884eeaefc2
Python List, Dictionary & Generator Comprehensions Explained (Eager vs Lazy Evaluation) | Geek Culture
February 26, 2026 - Master Python comprehensions and generators. Understand declarative construction, lazy evaluation, performance tradeoffs, and clean coding patterns.
๐ŸŒ
YouTube
youtube.com โ€บ trinity software academy
Dictionary Comprehension in Python with examples - YouTube
This video explains about the purpose of dictionary comprehension in python. 3 ways of creating a python dictionary is explained with examples.1. from single...
Published ย  March 30, 2022
Views ย  727
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-dictionary-comprehension
Python Dictionary Comprehension
August 18, 2025 - Learn Python dictionary comprehension with step-by-step examples. Create, filter, and transform dictionaries easily using one-liners in Python for learning.