How can I get list of values from dict?
You can use the values()
method to get a list of values from a dictionary:
my_dict = {"a": 1, "b": 2, "c": 3}
values_list = list(my_dict.values())
print(values_list)
This will output:
[1, 2, 3]
Watch a video course
Python - The Practical Guide
You can also use a list comprehension to get a list of values from a dictionary:
my_dict = {"a": 1, "b": 2, "c": 3}
values_list = [value for value in my_dict.values()]
print(values_list)
This will also output:
[1, 2, 3]
Both methods will provide you a list of values from the dict.