Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

python - 如何从字典中获取值列表?(How can I get list of values from dict?)

How can I get a list of the values in a dict in Python?

(如何在Python中获取字典中的值列表?)

In Java, getting the values of a Map as a List is as easy as doing list = map.values();

(在Java中,将Map的值作为列表获取就像执行list = map.values();一样容易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中是否有类似的简单方法可以从字典中获取值列表。)

  ask by Muhd translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes it's the exact same thing in Python 2 :

(是的,这与Python 2完全相同:)

d.values()

In Python 3 (where dict.values returns a view of the dictionary's values instead):

(在Python 3中 (其中dict.values返回一个字典值的视图 ):)

list(d.values())

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...