如何从字典中获取值列表? [英] How can I get list of values from dict?
本文介绍了如何从字典中获取值列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Python中获取字典中的值列表?
How can I get a list of the values in a dict in Python?
在Java中,将Map的值作为列表获取就像执行list = map.values();
一样容易.我想知道Python中是否有类似的简单方法可以从字典中获取值列表.
In Java, getting the values of a Map as a List is as easy as doing list = map.values();
. I'm wondering if there is a similarly simple way in Python to get a list of values from a dict.
推荐答案
是的,在在 Python 3 中(其中dict.values
返回一个改为 视图 字典的值):
In Python 3 (where dict.values
returns a view of the dictionary’s values instead):
list(d.values())
这篇关于如何从字典中获取值列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文