Computer >> Computer tutorials >  >> Programming >> Python

How to get a list of all the values from a Python dictionary?


To get a list of all keys from a dictionary, you can simply use the dict.values() function. 

Example

my_dict = {'name': 'TutorialsPoint', 'time': '15 years', 'location': 'India'}
value_list = list(my_dict.values())
print(value_list)

Output

This will give the output −

['TutorialsPoint', '15 years', 'India']

You can also get a list of all values in a dictionary using a list comprehension. 

Example

my_dict = {'name': 'TutorialsPoint', 'time': '15 years', 'location': 'India'}
value_list = [my_dict[key] for key in my_dict]
print(value_list)

Output

This will give the output −

['TutorialsPoint', '15 years', 'India']