In this tutorial, we will look at how to get the values of a Python dictionary with the help of some examples.
How to get the values of a dictionary in Python?

You can use the Python dictionary values()
function to get all the values in a Python dictionary. The following is the syntax:
# get all the values in a dictionary sample_dict.values()
It returns a dict_values
object containing all the values in the dictionary. This object is iterable, that is, you can use it to iterate through the values in the dictionary. You can use the list()
function to convert this object into a list.
Let’s look at some examples.
Using dictionary values()
method
Let’s create a dictionary containing the names to department mappings of employees at an office. The keys here are the employee names whereas the values are their respective departments.
Highlighted programs for you
Flatiron School
Flatiron School
University of Maryland Global Campus
University of Maryland Global Campus
Creighton University
Creighton University
Let’s get all the values in the dictionary using the dictionary’s values()
function.
# create a dictionary employees = { "Jim": "Sales", "Dwight": "Sales", "Angela": "Accounting" } # get values of dictionary print(employees.values())
Output:
dict_values(['Sales', 'Sales', 'Accounting'])
You can see that we get all the names of the departments (the values in the dictionary employee
) in a dict_values
object.
Now, you can also convert this object to a list using the Python built-in list()
function.
# dictionary values as list print(list(employees.values()))
Output:
['Sales', 'Sales', 'Accounting']
We now have the values in the dictionary employees
as a list.
Using Iteration
Alternatively, you can iterate through the dictionary items and append the value in each iteration to a result list.
# create a dictionary employees = { "Jim": "Sales", "Dwight": "Sales", "Angela": "Accounting" } # get values of dictionary val_ls = [] for key, val in employees.items(): val_ls.append(val) print(val_ls)
Output:
['Sales', 'Sales', 'Accounting']
We get the values in the dictionary as a list.
You can also reduce the above computation to a single line using list comprehension.
# get values of dictionary val_ls = [val for key, val in employees.items()] print(val_ls)
Output:
['Sales', 'Sales', 'Accounting']
We get the same result as above.
In this tutorial, we looked at different ways to get all the values in a Python dictionary. Using the dictionary’s values()
function is a simpler and a direct way of getting the values as compared to the iteration-based methods.
You might also be interested in –
- Get Keys of a Python Dictionary – With Examples
- Get Value for a Key in a Python Dictionary
- Python – Count Keys in a Dictionary
Subscribe to our newsletter for more informative guides and tutorials.
We do not spam and you can opt out any time.