Convert the keys of a dictionary to list

0 votes
I have a dictionary which has usernames and passwords. Now I want to get a list of these usernames. I want to create a list of these usernames from the dictionary. How can I do this?
Feb 7, 2019 in Python by Loki
502 views

1 answer to this question.

0 votes

Unpacking with * works with any object that is iterable and, since dictionaries return their keys when iterated through, you can easily create a list by using it within a list literal.

>>> newdict = {1:0, 2:0, 3:0}
>>> [*newdict]
[1, 2, 3]
answered Feb 7, 2019 by Omkar
• 69,220 points

Related Questions In Python

0 votes
1 answer

Convert dictionary keys to a list

list.(dictionary.keys()) READ MORE

answered Jun 28, 2018 in Python by Hamartia's Mask
• 1,580 points
561 views
0 votes
1 answer
+2 votes
2 answers

In a list of dictionaries, how can I find the minimum calue in a common dictionary field.

There are several options. Here is a ...READ MORE

answered Apr 10, 2018 in Python by charlie_brown
• 7,720 points
1,415 views
0 votes
1 answer

What is the recommended way to randomize a list of strings using Python?

Hi. Nice question. Here is the simplified answer ...READ MORE

answered Jan 18, 2019 in Python by Nymeria
• 3,560 points
934 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,438 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,073 views
+4 votes
3 answers

Write a for loop that prints all elements of a list and their position in the list. a = [4,7,3,2,5,9]

Try using this question by list comprehension: a=[4,7,3,2,5,9] print([x for ...READ MORE

answered Dec 9, 2019 in Python by vinaykumar
• 200 points
34,855 views
+1 vote
2 answers

How to convert list to string

mylist = [1, 2, 3] ‘’.join(map(str, mylist)) ==> ...READ MORE

answered Aug 21, 2018 in Python by Omkar
• 69,220 points
1,015 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