Post

PythonPython

p
persis crystal

Posted on 19th May 2024|27 views

0
votes

Dictionary Keys To List

How to get dictionary keys as a list in python?

Answers
P
kumar san

Posted on 19th May 2024

You can do it by using ditc.keys like this:

def getList(dict):

    return dict.keys()

dict = {1:'how', 2:'are', 3:'you'}

print(getList(dict))

Output:

[1, 2, 3]

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos