Python Dictionary Convert Keys to List Example

By Hardik Savani October 30, 2023 Category : Python

Hi Friends,

This tutorial will give you an example of python dictionary convert keys to list. you will learn python convert dict keys to list. I would like to share with you python save dict keys to list. you will learn how to convert python dictionary keys to list. Follow the below tutorial step of python dictionary convert keys to list.

There are several ways to convert python dictionary keys to list. I will give you the following three examples to convert dictionary to list in python.

1) Python Convert Dictionary Keys to List Example

2) Python Convert Dictionary Values to List Example

3) Python Convert Dictionary Items 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 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']

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 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')]

I hope it can help you...

Tags :
Shares