How to Convert Dictionary to List in Python?
Hello Dev,
This article will give you an example of python convert dictionary items to list. we will help you to give an example of python convert dict_items to list. you will learn how to convert dictionary to list in python. you can understand a concept of how to convert dict to list in python. you will do the following things for python convert dict object to list.
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.
1) Python Convert Dictionary Items to List Example
2) Python Convert Dictionary Values to List Example
3) Python Convert Dictionary Keys to List Example
So, without further ado, let's see simple examples:
You can use these examples with python3 (Python 3) version.
1) Python Convert Dictionary Items to List Example
main.py
myDictionary = { "id": 1, "name": "Hardik Savani", "email": "hardik@gmail.com" } # Python Convert Dictionary Items to List newDictionary = list(myDictionary.items()) print(newDictionary)
Output:
[('id', 1), ('name', 'Hardik Savani'), ('email', 'hardik@gmail.com')]
2) Python Convert Dictionary Values to List Example
main.py
myDictionary = { "id": 1, "name": "Hardik Savani", "email": "hardik@gmail.com" } # Python Convert Dictionary Values to List newDictionary = list(myDictionary.values()) print(newDictionary)
Output:
[1, 'Hardik Savani', 'hardik@gmail.com']
3) Python Convert Dictionary Keys to List Example
main.py
myDictionary = { "id": 1, "name": "Hardik Savani", "email": "hardik@gmail.com" } # Python Convert Dictionary Keys to List newDictionary = list(myDictionary.keys()) print(newDictionary)
Output:
['id', 'name', 'email']
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Python Dictionary Remove Duplicate Values Example
- Python Dictionary Check if Value is Empty Example
- How to Check if Python Dictionary is Empty or Not?
- Check if Key Value Pair Exists in Dictionary Python Example
- Python Dictionary Check if Value Exists Example
- Python Dictionary Check if Key Exists Example
- How to Update Value in Python Dictionary?
- How to Change Value in Python Dictionary?
- Python Dictionary Remove Element by Value Example
- Python Dictionary Delete Item by Key Example
- How to Remove Element from Python Dictionary?
- How to Add a Key Value Pair to Dictionary in Python?
- Python Create JSON File from Dict Example