Convert Dictionary to List in Python Tutorial Example
Hi Dev,
In this tute, we will discuss convert dictionary to list in python tutorial example. I would like to share with you python dictionary into list. We will use python convert dict object to list. We will look at example of how to convert dict to list in python. Let's get started with how to convert dictionary to list in python.
There are several ways to convert a python dictionary to list. I will give you the following three examples to convert a dictionary to list in python.
Example 1: Python Convert Dictionary Items to List
main.py
myDictionary = {
"id": 1,
"name": "Piyush Kamani",
"email": "[email protected]"
}
# Python Convert Dictionary Items to List
newDictionary = list(myDictionary.items())
print(newDictionary)
Output:
[('id', 1), ('name', 'Piyush Kamani'), ('email', '[email protected]')]
Example 2: Python Convert Dictionary Values to List
main.py
myDictionary = {
"id": 1,
"name": "Piyush Kamani",
"email": "[email protected]"
}
# Python Convert Dictionary Values to List
newDictionary = list(myDictionary.values())
print(newDictionary)
Output:
[1, 'Piyush Kamani', '[email protected]']
Example 3: Python Convert Dictionary Keys to List
main.py
myDictionary = {
"id": 1,
"name": "Piyush Kamani",
"email": "[email protected]"
}
# Python Convert Dictionary Keys to List
newDictionary = list(myDictionary.keys())
print(newDictionary)
Output:
['id', 'name', 'email']
- Get Last 2 Digits of Number in Python Tutorial Example
- How to Sum of First and Last Digit of Number in Python?
- How to Get First and Last Digit of Number in Python?
- Get the Last Digit of Number in Python Tutorial Example
- Get the First Digit of Number in Python Tutorial Example
- How to Remove All Decimals from Number in Python?
- How to Convert String to Float with 2 Decimal Places in Python?
- How to Format Number to 2 Decimal Places in Python?