How can I get list of values from dict?
You can use the values() method to get a list of values from a dictionary:
You can use the values() method to get a list of values from a dictionary:
Get list of values from dict in Python
my_dict = {"a": 1, "b": 2, "c": 3}
values_list = list(my_dict.values())
print(values_list)This will output:
[1, 2, 3]You can also use a list comprehension to get a list of values from a dictionary:
Get list of values from dict in Python using list comprehension
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.