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.