How to output the values of a dictionary as a list in Python?
You can use the values() method of a dictionary to retrieve all the values in the dictionary and convert them into a list. Here is an example code:
my_dict = {'a': 1, 'b': 2, 'c': 3}
# 将字典中的值转换为列表
values_list = list(my_dict.values())
print(values_list)
The output is: [1, 2, 3]
In the above example, we first create a dictionary called my_dict, then use the values() method to get all the values in the dictionary and convert them to a list. Finally, we print the list using the print() function.