{"id":5063,"date":"2023-10-26T15:29:41","date_gmt":"2023-10-26T09:59:41","guid":{"rendered":"https:\/\/python-programs.com\/?p=5063"},"modified":"2023-11-10T12:01:07","modified_gmt":"2023-11-10T06:31:07","slug":"convert-dictionary-values-to-a-list-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/convert-dictionary-values-to-a-list-in-python\/","title":{"rendered":"Convert Dictionary Values to a List in Python"},"content":{"rendered":"

Dictionaries are the implementation by Python of a data structure associative array. A dictionary is a collection of pairs of key values. A key pair and its associated value represent each key pair.<\/p>\n

The list of key value pairs in curly braces that is separated by comma defines a dictionary. Column \u2018:\u2019 separates the value of each key.<\/p>\n

A dictionary cannot be sorted only to get a representation of the sorted dictionary. Inherently, dictionaries are orderless, but not other types, including lists and tuples. Therefore, you need an ordered data type, which is a list\u2014probably a list of tuples.<\/p>\n

Given a dictionary, the task is to convert values of this dictionary to a list.<\/p>\n

Examples:<\/strong><\/p>\n

Example 1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

dictionary = <\/span>{<\/span>'this'<\/span>: <\/span>200<\/span>, <\/span>'is'<\/span>: <\/span>100<\/span>, <\/span>'BTechGeeks'<\/span>: <\/span>300<\/span>}<\/span><\/pre>\n

Output:<\/strong><\/p>\n

[200, 100, 300]<\/pre>\n

Example 2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

dictionary = <\/span>{<\/span>'this'<\/span>: <\/span>200<\/span>, <\/span>'is'<\/span>: <\/span>100<\/span>, <\/span>'BTechGeeks'<\/span>: <\/span>300 ,'python' :400<\/span>}<\/span><\/pre>\n

Output:<\/strong><\/p>\n

[200, 100, 300,400]<\/pre>\n

Convert Dictionary Values to a List in Python<\/h2>\n

There are several ways to convert dictionary values to a list some of them are:<\/p>\n