To get a list of all keys from a dictionary, you can simply use the dict.keys() function.
example
my_dict = {'name': 'TutorialsPoint', 'time': '15 years', 'location': 'India'} key_list = list(my_dict.keys()) print(key_list)
Output
This will give the output −
['name', 'time', 'location']
You can also get a list of all keys in a dictionary using a list comprehension.
example
my_dict = {'name': 'TutorialsPoint', 'time': '15 years', 'location': 'India'} key_list = [key for key in my_dict] print(key_list)
Output
This will give the output −
['name', 'time', 'location']