How to return dictionary keys as a list in Python

0 votes

Now, in Python >= 3.3, I get something like this:

>>> newdict.keys()
dict_keys([1, 2, 3])

So, I have to do this to get a list:

newlist = list()
for i in newdict.keys():
    newlist.append(i)

I'm wondering, is there a better way to return a list in Python 3?

Feb 18, 2022 in Python by Dev
• 6,000 points
262 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

How to correctly return an a dictionary as an output in zappier code using python?

David here, from the Zapier Platform team. ...READ MORE

answered Dec 3, 2018 in Python by charlie_brown
• 7,720 points
1,354 views
0 votes
1 answer
0 votes
1 answer

How can I add new keys to a dictionary in Python?

Yes, it is possible to add new ...READ MORE

answered Feb 9, 2022 in Python by Nandini
• 5,480 points
323 views
0 votes
1 answer

How to Print a List in Python

ou are using Python 2.x syntax with ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,720 points
781 views
0 votes
1 answer

How to Reverse a list in Python

You can use the reversed function in ...READ MORE

answered Sep 29, 2018 in Python by SDeb
• 13,300 points
644 views
0 votes
1 answer

List comprehension on a nested list - How to do it in Python?

Not sure what your desired output is, ...READ MORE

answered Nov 21, 2018 in Python by Nymeria
• 3,560 points
1,259 views
0 votes
1 answer

Python: Sort list of lists numerically

You can try and De-dupe it with ...READ MORE

answered May 20, 2019 in Python by SDeb
• 13,300 points
2,017 views
0 votes
0 answers

Double the value of array on a match - Python

I want to iterate through the elements ...READ MORE

Apr 24, 2022 in Python by Kichu
• 19,050 points
1,536 views
0 votes
0 answers
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,090 points
1,457 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP