This will convert the dict_keys object to a list:

Copylist(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:

Copyfor 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
🌐
Built In
builtin.com › software-engineering-perspectives › convert-list-to-dictionary-python
10 Ways to Convert Lists to Dictionaries in Python | Built In
Converting a list to a dictionary with the same value for all keys. Converting a list to a dictionary using dict.fromkeys(). Converting a nested list to a dictionary using dictionary comprehension. Converting a list to a dictionary using Counter(). An introduction on how to convert a list to dictionary in Python.
🌐
Career Karma
careerkarma.com › blog › python › python convert list to dictionary: a complete guide
Python Convert List to Dictionary: A Complete Guide: A Complete Guide
December 1, 2023 - The value assigned to each fruit should be In stock: ... We could create this dictionary using the dict.fromkeys() method. This method accepts a list of keys that you want to turn into a dictionary.
Discussions

Why can't I use a list as a dict key in python? Exactly what can and cannot be used, and why? - Stack Overflow
I had some vague idea that that ... would go wrong if Python allowed using lists as keys, say, using their memory location as the hash? ... There's a good article on the topic in the Python wiki: Why Lists Can't Be Dictionary Keys.... More on stackoverflow.com
🌐 stackoverflow.com
How can i retrieve all the values of a key for a list of dictionaries nested in a dictionary
No. You will need a loop. A list comprehension is probably the neatest: prices = [d['price'] for d in dict['data']] (Although you shouldn't use the name dict for your dictionary, as it shadows the built-in function.) More on reddit.com
🌐 r/learnpython
12
0
April 12, 2025
How do you add a list as the value of a key inside a dictionary? What about tuples of lists?
What is the difference between dict[key].append(list) and value.append(list)? They have the same result, yes, but the first is doing unnecessary work. The dict[key] part of the expression is fetching the value for the key, but you already have that in value, so just append to that. how would I add a second list to one of these values as a tuple? The value is a list, so just append whatever object you want. So if the object to append is a list just do: new_list = ['c', 'd'] for (key, value) ...: value.append(new_list) That's what you are already doing, so I'm not sure what your problem actually is. More on reddit.com
🌐 r/learnpython
8
2
April 3, 2022
How to turn a list of lists into a dictionary where the first item of each sublist is used as key?
We can use tuple assignment with packing inside a dictionary comprehension, eg. data = [['James', '100.00', '90.00', '85.50'], ['Nick', '78.00', '85.00', '80.50'], ['William', '95.50', '92.00', '100.00']] data_dict = {name: values for name, *values in data} More on reddit.com
🌐 r/learnpython
5
4
November 28, 2022
Top answer
1 of 13
1721

This will convert the dict_keys object to a list:

Copylist(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:

Copyfor 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
557

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:

Copy>>> 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:

Copy%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:

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

beware of the trailing comma in the tuple case!

🌐
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 - We can change the list into immutable objects like string or tuple and then can use it as a key. Below is the implementation of the approach. ... # Declaring a dictionary d = {} # This is the list which we are # trying to use as a key to # the dictionary a =[1, 2, 3, 4, 5] # converting the list a to a string p = str(a) d[p]= 1 # converting the list a to a tuple q = tuple(a) d[q]= 1 for key, value in d.items(): print(key, ':', value)
🌐
W3Schools
w3schools.com › python › python_dictionaries.asp
Python Dictionaries
Python Overview Python Built-in Functions Python String Methods Python List Methods Python Dictionary Methods Python Tuple Methods Python Set Methods Python File Methods Python Keywords Python Exceptions Python Glossary · Built-in Modules Random Module Requests Module Statistics Module Math Module cMath Module · Remove List Duplicates Reverse a String Add Two Numbers · Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... Dictionaries are used to store data values in key:value pairs.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-convert-a-list-to-dictionary
Convert a List to Dictionary Python - GeeksforGeeks
For example, we are given a list a=[10,20,30] we need to convert the list in dictionary so that the output should be a dictionary like {0: 10, 1: 20, 2: 30}. We can use methods like enumerate, zip to convert a list to dictionary in python.
Published   July 12, 2025
🌐
TutorialsPoint
tutorialspoint.com › article › how-to-use-a-list-as-a-dictionary-key-in-python-3
How to use a List as a dictionary key in Python 3?
March 27, 2026 - Lists cannot be used directly as dictionary keys because they are mutable. Convert lists to immutable types like tuples, strings, or JSON strings to use them as keys.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-convert-list-to-single-dictionary-key-value-list
Convert List to Single Dictionary Key - Value list - Python - GeeksforGeeks
July 15, 2025 - A set is created with the Kth element and another set is formed with all the elements except the one at index K then we take the difference between the sets to identify the remaining values. Finally, we create a dictionary where the key is the Kth element, and the value is the remaining list of elements.
🌐
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 ...
🌐
Real Python
realpython.com › python-dicts
Dictionaries in Python – Real Python
April 8, 2026 - Python lists are unhashable because any changes to their content would change their hash value, violating the requirement that hash values must remain constant for hashable types. In practice, you can’t use any mutable data type as a key in a dictionary.
🌐
Python documentation
docs.python.org › 3 › tutorial › datastructures.html
5. Data Structures — Python 3.14.6 documentation
You can’t use lists as keys, since lists can be modified in place using index assignments, slice assignments, or methods like append() and extend(). It is best to think of a dictionary as a set of key: value pairs, with the requirement that the keys are unique (within one dictionary).
🌐
Medium
medium.com › @atatus › https-www-atatus-com-blog-python-converting-lsts-to-dictionaries-c3f038a8ce30
Python: Converting Lists to Dictionaries | by Atatus | Medium
September 16, 2024 - In simple words, the dictionary ... a list to a dictionary python is to use a for loop to iterate through the list and create dictionary from list python and from its elements....
🌐
Python
wiki.python.org › moin › DictionaryKeys
DictionaryKeys - Python Wiki
Note that since tuples are immutable, they do not run into the troubles of lists - they can be hashed by their contents without worries about modification. Thus, in Python, they provide a valid __hash__ method and are thus usable as dictionary keys. ... By default, all user defined types are usable as dictionary keys with hash(object) defaulting to id(object), and cmp(object1, object2) defaulting to cmp(id(object1), id(object2)).
🌐
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!

Top answer
1 of 4
176

If you are still thinking what the! You would not be alone, its actually not that complicated really, let me explain.

How to turn a list into a dictionary using built-in functions only

We want to turn the following list into a dictionary using the odd entries (counting from 1) as keys mapped to their consecutive even entries.

Copyl = ["a", "b", "c", "d", "e"]

dict()

To create a dictionary we can use the built in dict function for Mapping Types as per the manual the following methods are supported.

Copydict(one=1, two=2)
dict({'one': 1, 'two': 2})
dict(zip(('one', 'two'), (1, 2)))
dict([['two', 2], ['one', 1]])

The last option suggests that we supply a list of lists with 2 values or (key, value) tuples, so we want to turn our sequential list into:

Copyl = [["a", "b"], ["c", "d"], ["e",]]

We are also introduced to the zip function, one of the built-in functions which the manual explains:

returns a list of tuples, where the i-th tuple contains the i-th element from each of the arguments

In other words if we can turn our list into two lists a, c, e and b, d then zip will do the rest.

slice notation

Slicings which we see used with Strings and also further on in the List section which mainly uses the range or short slice notation but this is what the long slice notation looks like and what we can accomplish with step:

Copy>>> l[::2]
['a', 'c', 'e']

>>> l[1::2]
['b', 'd']

>>> zip(['a', 'c', 'e'], ['b', 'd'])
[('a', 'b'), ('c', 'd')]

>>> dict(zip(l[::2], l[1::2]))
{'a': 'b', 'c': 'd'}

Even though this is the simplest way to understand the mechanics involved there is a downside because slices are new list objects each time, as can be seen with this cloning example:

Copy>>> a = [1, 2, 3]
>>> b = a
>>> b
[1, 2, 3]

>>> b is a
True

>>> b = a[:]
>>> b
[1, 2, 3]

>>> b is a
False

Even though b looks like a they are two separate objects now and this is why we prefer to use the grouper recipe instead.

grouper recipe

Although the grouper is explained as part of the itertools module it works perfectly fine with the basic functions too.

Some serious voodoo right? =) But actually nothing more than a bit of syntax sugar for spice, the grouper recipe is accomplished by the following expression.

Copy*[iter(l)]*2

Which more or less translates to two arguments of the same iterator wrapped in a list, if that makes any sense. Lets break it down to help shed some light.

zip for shortest

Copy>>> l*2
['a', 'b', 'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e']

>>> [l]*2
[['a', 'b', 'c', 'd', 'e'], ['a', 'b', 'c', 'd', 'e']]

>>> [iter(l)]*2
[<listiterator object at 0x100486450>, <listiterator object at 0x100486450>]

>>> zip([iter(l)]*2)
[(<listiterator object at 0x1004865d0>,),(<listiterator object at 0x1004865d0>,)]

>>> zip(*[iter(l)]*2)
[('a', 'b'), ('c', 'd')]

>>> dict(zip(*[iter(l)]*2))
{'a': 'b', 'c': 'd'}

As you can see the addresses for the two iterators remain the same so we are working with the same iterator which zip then first gets a key from and then a value and a key and a value every time stepping the same iterator to accomplish what we did with the slices much more productively.

You would accomplish very much the same with the following which carries a smaller What the? factor perhaps.

Copy>>> it = iter(l)     
>>> dict(zip(it, it))
{'a': 'b', 'c': 'd'}

What about the empty key e if you've noticed it has been missing from all the examples which is because zip picks the shortest of the two arguments, so what are we to do.

Well one solution might be adding an empty value to odd length lists, you may choose to use append and an if statement which would do the trick, albeit slightly boring, right?

Copy>>> if len(l) % 2:
...     l.append("")

>>> l
['a', 'b', 'c', 'd', 'e', '']

>>> dict(zip(*[iter(l)]*2))
{'a': 'b', 'c': 'd', 'e': ''}

Now before you shrug away to go type from itertools import izip_longest you may be surprised to know it is not required, we can accomplish the same, even better IMHO, with the built in functions alone.

map for longest

I prefer to use the map() function instead of izip_longest() which not only uses shorter syntax doesn't require an import but it can assign an actual None empty value when required, automagically.

Copy>>> l = ["a", "b", "c", "d", "e"]
>>> l
['a', 'b', 'c', 'd', 'e']

>>> dict(map(None, *[iter(l)]*2))
{'a': 'b', 'c': 'd', 'e': None} 

Comparing performance of the two methods, as pointed out by KursedMetal, it is clear that the itertools module far outperforms the map function on large volumes, as a benchmark against 10 million records show.

Copy$ time python -c 'dict(map(None, *[iter(range(10000000))]*2))'
real    0m3.755s
user    0m2.815s
sys     0m0.869s
$ time python -c 'from itertools import izip_longest; dict(izip_longest(*[iter(range(10000000))]*2, fillvalue=None))'
real    0m2.102s
user    0m1.451s
sys     0m0.539s

However the cost of importing the module has its toll on smaller datasets with map returning much quicker up to around 100 thousand records when they start arriving head to head.

Copy$ time python -c 'dict(map(None, *[iter(range(100))]*2))'
real    0m0.046s
user    0m0.029s
sys     0m0.015s
$ time python -c 'from itertools import izip_longest; dict(izip_longest(*[iter(range(100))]*2, fillvalue=None))'
real    0m0.067s
user    0m0.042s
sys     0m0.021s

$ time python -c 'dict(map(None, *[iter(range(100000))]*2))'
real    0m0.074s
user    0m0.050s
sys     0m0.022s
$ time python -c 'from itertools import izip_longest; dict(izip_longest(*[iter(range(100000))]*2, fillvalue=None))'
real    0m0.075s
user    0m0.047s
sys     0m0.024s

See nothing to it! =)

nJoy!

2 of 4
53

Using the usual grouper recipe, you could do:

Python 2:

Copyd = dict(itertools.izip_longest(*[iter(l)] * 2, fillvalue=""))

Python 3:

Copyd = dict(itertools.zip_longest(*[iter(l)] * 2, fillvalue=""))
🌐
Google
developers.google.com › google for education › python › python dict and file
Python Dict and File | Python Education | Google for Developers
## Note that the keys are in a random order. for key in dict: print(key) ## prints a g o ## Exactly the same as above for key in dict.keys(): print(key) ## Get the .keys() list: print(dict.keys()) ## dict_keys(['a', 'o', 'g']) ## Likewise, there's a .values() list of values print(dict.values()) ## dict_values(['alpha', 'omega', 'gamma']) ## Common case -- loop over the keys in sorted order, ## accessing each key/value for key in sorted(dict.keys()): print(key, dict[key]) ## .items() is the dict expressed as (key, value) tuples print(dict.items()) ## dict_items([('a', 'alpha'), ('o', 'omega'),
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-get-dictionary-keys-as-a-list
Dictionary keys as a list in Python - GeeksforGeeks
List Comprehension provide concise and readable way to create a list of keys. ... Iterating directly over the dictionary yields its keys.
Published   July 11, 2025