Fix Python – How can I get list of values from dict?

Question

Asked By – Muhd

How can I get a list of the values in a dict in 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.

Now we will see solution for issue: How can I get list of values from dict?


Answer

dict.values returns a view of the dictionary’s values, so you have to wrap it in list:

list(d.values())

This question is answered By – jamylak

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0