Obtain list of keys of a Dictionary in Python
In this tutorial, we will see how to obtain list of keys of a Dictionary in Python
• 1 min read
To obtain list of keys of a Dictionary in Python, the dictionary offers keys()
method. It returns a collection of type dict_keys
.
If we want to get all the keys of a dictionary as a type of list
, we can do so using list comprehension as follows.
The output of the preceding code will return a collection of keys
of type list
as shown as follows.