Related questions
How to return dictionary keys as a list in Python?
In Python 2.7, I could get dictionary keys, values, or items as a list:
>>> newdict = {1:0, 2:0, 3:0}
>>> newdict.keys()
[1, 2, 3]
Now, in Python >= 3.3, I get something like this:
>>> newdict.keys()
dict_keys([1, 2, 3])
So, I …
Convert two lists into a dictionary
Imagine that you have:
keys = ['name', 'age', 'food']
values = ['Monty', 42, 'spam']
What is the simplest way to produce the following dictionary?
a_dict = {'name' : 'Monty', 'age' : 42, 'food' : 'spam'}