Skip to main content

How to Get All the Values of a Dictionary in Python with values()

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

A dictionary pairs keys with values, and sometimes you only want the values: every amount in stock, every score in a game. values() gives you all of them at once, ready to add up, loop over or turn into a list. This guide does all three on Python 3.15.2.

Syntax​

Syntax
<values> = <dictionary>.values()
PartWhat it means
<dictionary>Any dictionary
values()Returns a view of the values, in the dictionary's order

The built-in types reference says values() will "Return a new view of the dictionary's values."

The Example​

A shop's stock maps each item to how many are left: helmets, locks and lights. The script prints the values, their total and the values as a list.

Prerequisites​

  • uv and Python 3. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with uv init.

Step 1: Write the Script​

values.py
stock = {"helmets": 4, "locks": 9, "lights": 6}

print(stock.values())
print(sum(stock.values()))
print(list(stock.values()))

The values.py script in a macOS-style code window: a stock dictionary with helmets 4, locks 9 and lights 6, then prints of stock.values(), its sum and its list.

Step 2: Run It​

Terminal
uv run python values.py
Output
dict_values([4, 9, 6])
19
[4, 9, 6]

The terminal after uv run python values.py: dict_values([4, 9, 6]), then 19, then [4, 9, 6].

values() returned a dict_values view of 4, 9 and 6, in the order the keys were added. sum added them up to 19, and list copied them into a plain list. The command works unchanged in PowerShell.

A View, Not a Copy​

The view follows the dictionary. Taking amounts = stock.values() from a two-item dictionary, then adding stock["lights"] = 6, and printing amounts afterwards showed the new value too:

Output
dict_values([4, 9, 6])

Common Mistakes​

MistakeWhat happensDo this instead
Taking an item by position: stock.values()[0]TypeError: 'dict_values' object is not subscriptableTurn it into a list first: list(stock.values())[0]
Expecting a copy that stays the sameThe view shows later changes to the dictionaryUse list(stock.values()) for a fixed copy

Troubleshooting​

SymptomLikely causeFix
'dict_values' object is not subscriptable[ ] used on the viewWrap it in list()

FAQ​

How do I get the keys or both?​

keys() returns the keys, and items() returns key and value pairs; both are views like values().

Can I loop over it?​

Yes: for amount in stock.values(): goes through 4, 9 and 6.

Conclusion​

stock.values() returned all three amounts as a view that sum added up to 19 and list turned into [4, 9, 6]. Wrap it in list() when you need positions or a copy that doesn't change.

Additional Resources​