How can I get list of values from dict?
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
To get a list of values from a Python dictionary, use list(d.values()). The dict.values() method returns a view object, not a list. In Python 3, you must wrap it with list() if you need indexing, slicing, or other list operations. For most iteration purposes, the view object works directly without conversion.
Basic Usage
View Object vs List
The view is a live window into the dictionary. A list is an independent copy.
When You Need a List vs When You Don't
Getting Keys and Values Together
Getting Specific Values by Keys
Filtering Values
Nested Dictionary Values
Python 2 vs Python 3
Common Pitfalls
- Forgetting that
dict.values()returns a view, not a list: In Python 3,d.values()returns adict_valuesobject. You cannot index it (d.values()[0]) or slice it. Wrap withlist()when you need list operations. - Assuming dictionary order is random: Since Python 3.7, dictionaries maintain insertion order.
list(d.values())returns values in the order they were inserted. In Python 3.5 and earlier, the order was undefined. - Modifying a dictionary while iterating over values: Adding or removing keys during
for v in d.values()raisesRuntimeError: dictionary changed size during iteration. Create a list copy first:for v in list(d.values()):. - Using
list(d.values())when iteration suffices: Converting to a list creates a copy of all values in memory. For simple iteration,for v in d.values():uses less memory because the view does not copy data. - Confusing
d.values()withd.items():d.values()returns only the values.d.items()returns (key, value) tuples. If you need both keys and values, used.items()instead of separate calls tod.keys()andd.values().
Summary
list(d.values())converts dictionary values to a listd.values()returns a live view object — no copy, reflects dictionary changes- Use the view directly for iteration, membership tests, and
len()— no need forlist() - Convert to list only when you need indexing, slicing, or an independent snapshot
- Use
sorted(d.values())to get a sorted list without modifying the dictionary - Python 3.7+ guarantees insertion order for
dict.values()
Related reading
- How can I get the concatenation of two lists in Python without modifying either one?
- How can I get the current stack trace in Java?
- How can I implement a queue using two stacks?
- How can I implement a tree in Python?
- How can I get pods by label, using the python kubernetes api?
- How can I get the name of a variable passed into a function?
- How can I iterate over overlapping current, next pairs of values from a list?
- How can I join int to a character-separated string in .NET?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.