This will convert the dict_keys object to a list:

list(newdict.keys())

On the other hand, you should ask yourself whether or not it matters. It is Pythonic to assume duck typing -- if it looks like a duck and it quacks like a duck, it is a duck. The dict_keys object can be iterated over just like a list. For instance:

for key in newdict.keys():
    print(key)

Note that dict_keys doesn't support insertion newdict[k] = v, though you may not need it.

Answer from Chris on Stack Overflow
Top answer
1 of 13
1714

This will convert the dict_keys object to a list:

list(newdict.keys())

On the other hand, you should ask yourself whether or not it matters. It is Pythonic to assume duck typing -- if it looks like a duck and it quacks like a duck, it is a duck. The dict_keys object can be iterated over just like a list. For instance:

for key in newdict.keys():
    print(key)

Note that dict_keys doesn't support insertion newdict[k] = v, though you may not need it.

2 of 13
556

Python >= 3.5 alternative: unpack into a list literal [*newdict]

New unpacking generalizations (PEP 448) were introduced with Python 3.5 allowing you to now easily do:

>>> newdict = {1:0, 2:0, 3:0}
>>> [*newdict]
[1, 2, 3]

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.

Adding .keys() i.e [*newdict.keys()] might help in making your intent a bit more explicit though it will cost you a function look-up and invocation. (which, in all honesty, isn't something you should really be worried about).

The *iterable syntax is similar to doing list(iterable) and its behaviour was initially documented in the Calls section of the Python Reference manual. With PEP 448 the restriction on where *iterable could appear was loosened allowing it to also be placed in list, set and tuple literals, the reference manual on Expression lists was also updated to state this.


Though equivalent to list(newdict) with the difference that it's faster (at least for small dictionaries) because no function call is actually performed:

%timeit [*newdict]
1000000 loops, best of 3: 249 ns per loop

%timeit list(newdict)
1000000 loops, best of 3: 508 ns per loop

%timeit [k for k in newdict]
1000000 loops, best of 3: 574 ns per loop

with larger dictionaries the speed is pretty much the same (the overhead of iterating through a large collection trumps the small cost of a function call).


In a similar fashion, you can create tuples and sets of dictionary keys:

>>> *newdict,
(1, 2, 3)
>>> {*newdict}
{1, 2, 3}

beware of the trailing comma in the tuple case!

๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-get-dictionary-keys-as-a-list
Dictionary keys as a list in Python - GeeksforGeeks
The simplest and most efficient way to convert dictionary keys to lists is by using a built-in list() function.
Published ย  July 11, 2025
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python get dictionary keys as a list
Python Get Dictionary Keys as a List - Spark By {Examples}
May 31, 2024 - How to get Python Dictionary Keys as a List? To get all dictionary keys as a list in Python use the keys() method and covert the returned object to a list
๐ŸŒ
Quora
quora.com โ€บ Can-a-list-be-a-key-in-a-dictionary-in-Python
Can a list be a key in a dictionary in Python? - Quora
Answer (1 of 4): No. Python lists are mutable objects and the list type does not implement a special __hash__ method. Keys must be hashable (must return a valid value from the builtin hash() function). Tuples are immutable sequences which can be used as dictionary keys.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how do you add a list as the value of a key inside a dictionary? what about tuples of lists?
r/learnpython on Reddit: How do you add a list as the value of a key inside a dictionary? What about tuples of lists?
April 3, 2022 -

I am trying to add a list, or a tuple of lists, as the value to a key inside a dictionary. I'm starting with a dictionary that has empty lists as values, and then adding to the value of each key inside a loop like this:

dict = {'key1': [], 'key2': [], 'key3': []}
list = ['a', 'b']
for key,value in dict.items():
#    dict[key].append(list)
    value.append(list)
print(dict)

What is the difference between dict[key].append(list) and value.append(list)? They both produce the same dictionary when the other is commented out.

Further, how would I add a second list to one of these values as a tuple? Something like adding the list ['c', 'd'] to key2, like this:

{'key1': [['a', 'b']], 'key2': [['a', 'b'], ['c', 'd']], 'key3': [['a', 'b']]}

Thanks for any replies!

๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-dictionary-keys-to-list
Python Dictionary Keys to List
To convert Python Dictionary keys to List, you can use dict.keys() method which returns a dict_keys object. This object can be iterated, and if you pass it to list() constructor, it returns a list object with dictionary keys as elements. Or you can use list comprehension, or use a for loop ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_dictionary_keys.asp
Python Dictionary keys() Method
Python Examples Python Compiler ... "model": "Mustang", "year": 1964 } x = car.keys() print(x) Try it Yourself ยป ยท The keys() method returns a view object....
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-get-a-list-of-all-the-keys-from-a-python-dictionary
How to get a list of all the keys from a Python dictionary?
In Python Dictionary, the dict.keys() method provides a view object that displays a list of all the keys in the dictionary in order of insertion.
Find elsewhere
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-convert-dict-keys-to-list-434461
How to convert dict keys to list | LabEx
## Using generator expressions for large dictionaries large_dict = {str(i): i for i in range(10000)} ## Memory-efficient key extraction key_generator = (key for key in large_dict.keys()) first_100_keys = list(next(key_generator) for _ in range(100)) When working with complex dictionary key operations, always consider memory usage and performance, especially when dealing with large datasets. Choose the most appropriate technique based on your specific requirements. By mastering these Python dictionary key conversion techniques, developers can easily transform dictionary keys into lists, enabling more flexible data handling and processing.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ how to get the key of a dictionary put into a list?
r/learnpython on Reddit: How to get the key of a dictionary put into a list?
May 26, 2021 -

I am trying to key just the key of a dictionary added to a list. But struggling. Ive tried iterating through dict[i] and it outs the value not key so i did a little reading and saw using .keys() but that adds all my keys .

The idea here is that this, if alabama appears makes up 40% of the population, i want it added to a list 40 times. If arizona makes 53% i want it added 53 times so when i do a random choice it will (roughly) pick bama 40 out 100 times and arizona 53 out of 100 times and so on. Currently I am only using 3 states and will eventually use all 50.

ex:

dict = {key:value}

list = [key1,key1,key2,key3,key3,key3,....]

my code

states = {"Alabama":4779736, "Alaska":710231, "Arizona":6392017,}
tot_pop = 0
pop_percent = states #saves dict as new dict so it is not over written
for i in pop_percent: #adds all indiv states pop to get total
    tot_pop += pop_percent[i]
for i in pop_percent: #divices indiv state pop by total
    ratio = pop_percent[i]/tot_pop
    pop_percent[i] = ratio #replaces value with percent
    percent = ratio * 100
    print(percent)
state_list = []
for i in range(int(percent)):
    keys = states.keys()
    state_list.append()
print(state_list)

results(only put a sample since it was a little difficult to read through)

[dict_keys(['Alabama', 'Alaska', 'Arizona']), dict_keys(['Alabama', 'Alaska', 'Arizona']), dict_keys(['Alabama', 'Alaska', 'Arizona'])]
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ standard-library โ€บ dict โ€บ keys
Python dict keys() - Retrieve Dictionary Keys | Vultr Docs
November 11, 2024 - The keys() method returns a view of the dictionary's keys, which reflects any changes made to the dictionary. Obtain the keys from a dictionary using keys(). Use the list() function to convert the keys to a list.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-use-a-list-as-a-key-of-a-dictionary-in-python-3
How to use a List as a key of a Dictionary in Python 3? - GeeksforGeeks
July 12, 2025 - Dictionaries use key:value pair to search if a key is present or not and if the key is present what is its value . We can use integer, string, tuples as dictionary keys but cannot use list as a key of it .
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ what is python dictionary keys() method?
What is Python Dictionary keys() Method? - Analytics Vidhya
January 31, 2024 - When it comes to performance, the keys() method is the most efficient way to retrieve dictionary keys as a list. It provides a view object that directly references the keys of the dictionary, without creating a new list.
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ dictionary โ€บ keys
Python Dictionary keys() (With Examples)
The keys() method extracts the keys of the dictionary and returns the list of keys as a view object. In this tutorial, you will learn about the Python Dictionary keys() method with the help of examples.
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ 5 easy ways to convert a dictionary to a list in python
5 Easy ways to convert a dictionary to a list in Python - AskPython
February 16, 2023 - By default, the key: value pairs are stored in the form of a Python tuple in the iterator returned by the dict.items() function. We can pass this returned iterator to the list() function which will finally give us a Python list of tuples containing ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-convert-key-value-list-dictionary-to-list-of-lists
Python - Convert Key-Value list Dictionary to List of Lists - GeeksforGeeks
July 12, 2025 - The result is then converted to a list, creating a list of lists with key-value pairs. ... # Define a dictionary with key-value pairs a = {'name': 'Alice', 'age': 25, 'city': 'New York'} # Use map to iterate over each item (key-value pair) in the dictionary res = list(map(lambda item: [item[0], item[1]], a.items())) print(res)
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-convert-python-dictionary-to-a-list
How to convert Python Dictionary to a list?
Get all the key-value pairs of a dictionary using the items() function(returns a group of the key-value pairs in the dictionary) and convert the dictionary items(key-value pair) to a list of tuples using the list() function(returns a list of an iteratable). Print the resultant list of a dictionary ...
๐ŸŒ
30 Seconds of Code
30secondsofcode.org โ€บ home โ€บ list โ€บ list to dictionary
Python - Convert between lists and dictionaries - 30 seconds of code
July 4, 2024 - Instead of simply using zip(), you can apply the function to each value of the list using map() before combining the values into a dictionary. def map_dictionary(itr, fn): return dict(zip(itr, map(fn, itr))) map_dictionary([1, 2, 3], lambda ...