dict.values()
dict.values() dict_values · Updated March 13, 2026 · Dict Methods The .values() method returns a view object that displays a list of all values in a dictionary. This view provides a dynamic view of the dictionary’s values, meaning it reflects any changes made to the dictionary.
Syntax
dict.values()
Parameters
None. This method takes no parameters.
Return Value
Returns a dict_values view object, which yields dictionary values on iteration. The view is dynamic—if the dictionary changes, the view reflects those changes.
Basic Examples
Getting all values from a dictionary
person = {"name": "Alice", "age": 30, "city": "New York"}
print(person.values())
# dict_values(['Alice', 30, 'New York'])
Iterating over values
The most common use is iterating over dictionary values:
scores = {"Alice": 95, "Bob": 87, "Charlie": 92}
for value in scores.values():
print(value)
# 95
# 87
# 92
Converting values to a list
If you need an actual list instead of a view:
fruits = {"apple": 1, "banana": 2, "cherry": 3}
values_list = list(fruits.values())
print(values_list)
# [1, 2, 3]
How Views Work
A key distinction: .values() returns a view, not a copy. Changes to the dictionary are reflected in the view:
d = {"a": 1, "b": 2}
values_view = d.values()
# Add a new key-value pair to the dictionary
d["c"] = 3
# The view now shows the new value!
print(list(values_view))
# [1, 2, 3]
If you need a snapshot that won’t change, convert to a list first:
d = {"a": 1}
snapshot = list(d.values())
d["b"] = 2
# Snapshot unchanged
print(snapshot)
# [1]
Common Patterns
Getting the sum of all values
inventory = {"apples": 5, "bananas": 3, "oranges": 8}
total = sum(inventory.values())
print(total)
# 16
Finding the maximum or minimum value
temperatures = {"Monday": 20, "Tuesday": 18, "Wednesday": 22, "Thursday": 19}
highest = max(temperatures.values())
lowest = min(temperatures.values())
print(f"Highest: {highest}, Lowest: {lowest}")
# Highest: 22, Lowest: 18
Checking if a value exists
users = {"alice": "admin", "bob": "user", "charlie": "user"}
if "admin" in users.values():
print("At least one admin exists")
# At least one admin exists
Using values() with other dict methods
data = {"x": 10, "y": 20, "z": 30}
# Get keys and values together
keys = list(data.keys())
values = list(data.values())
print(keys)
# ['x', 'y', 'z']
print(values)
# [10, 20, 30]
Dictionary comprehension with values
prices = {"apple": 1.5, "banana": 0.5, "cherry": 3.0}
# Create new dict with doubled values
doubled = {k: v * 2 for k, v in prices.items()}
print(doubled)
# {'apple': 3.0, 'banana': 1.0, 'cherry': 6.0}
Filtering by value
scores = {"Alice": 95, "Bob": 72, "Charlie": 88, "Diana": 91}
# Keep only scores above 80
passing = {k: v for k, v in scores.items() if v > 80}
print(passing)
# {'Alice': 95, 'Charlie': 88, 'Diana': 91}
Using zip to combine keys with values
keys = ["name", "age", "city"]
values = ["Alice", 30, "New York"]
# Combine into a dictionary
data = dict(zip(keys, values))
print(data)
# {'name': 'Alice', 'age': 30, 'city': 'New York'}
values() vs keys() vs items()
| Method | Returns | Example |
|---|---|---|
.keys() | View of keys | ['name', 'age'] |
.values() | View of values | ['Alice', 30] |
.items() | View of (key, value) tuples | [('name', 'Alice'), ('age', 30)] |
Performance Note
The .values() view is memory-efficient because it doesn’t create a copy of the data. For large dictionaries, this can save significant memory. The view supports common operations like iteration, len(), and membership tests:
d = {"a": 1, "b": 2, "c": 3}
# Iterate directly over values
for value in d.values():
print(value)
# Get the count of values
print(len(d.values()))
# 3
See Also
- dict.keys() — returns a view of all keys in the dictionary
- dict.items() — returns key-value pairs as tuples
- dict() — the dict constructor for creating new dictionaries