Skip to content
Related Articles

Related Articles

How can to get list of values from dictionary in Python?

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 01 Dec, 2021

In this article, we will discuss how to get a list of values from a dictionary using Python.

Method 1 : Using list() function

We can use dictionary.values() along with list() function to get the list. Here, values() method is an dictionary method used to access the values from key:value pairs and we are then converting the values to list by using list() function

Syntax:

list(dictionary.values())

Example: Python program to create a dictionary with student names as key and values as subjects

Python3




# create a dictionary
# with student names as key
# values as subjects
data = {'manoja': 'java', 'tripura': 'python',
        'manoj': 'statistics', 'manoji': 'cpp'}
 
# get list of values
list(data.values())


Output:

['java', 'python', 'statistics', 'cpp']

Method 2: using [] 

We can use [] along with * to get all list of dictionary values. Here values() is a dictionary method is used to get the values from key:value pair in the dictionary and * is used to get only values instead of getting dict_values and then we are getting into a list by using list() function

Syntax:

[*dictionary.values()]

Example:

Python3




# create a dictionary
# with student names as key
# values as subjects
data = {'manoja': 'java', 'tripura': 'python',
        'manoj': 'statistics', 'manoji': 'cpp'}
 
# get list of values
[*data.values()]


Output:


Method 3: Using List comprehension

Using List comprehension we can get the list of dictionary values. Here we are using an list comprehension to iterate in a dictionary by using iterator. This will return each value from the key:value pair.

Syntax:

[dictionary[i] for i in dictionary]

Example:

Python3




# create a dictionary
# with student names as key
# values as subjects
data = {'manoja': 'java', 'tripura': 'python',
        'manoj': 'statistics', 'manoji': 'cpp'}
 
# get list of values using comprehension
[data[i] for i in data]


Output:

['java', 'python', 'statistics', 'cpp']


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!