In this article we will discuss how to create a list of all the values in dictionary.

Suppose we have a dictionary of string and integers i.e.

Now we want all the Values from above dictionary in a list i.e.

Let’s see how to do that,

Create a list of all values in dict using dict.values()

In python, dictionary class provides a member function i.e.

It returns a view object / iterator to the list of all values in dictionary.  We can use this object for iteration or creating new list.

Let’s use that to get the list of all values in the above dictionary.

dictValues content will be,

Creating a list of duplicate values in dictionary

Suppose instead of all values we want a list of all duplicate values from the dictionary i.e.

[23 , 2]

Let’s do that using for loop i.e.

dictkeys content will be,

Complete example is as follows,

Output:

 

Click Here to Subscribe for more Articles / Tutorials like this.