Answer the question
In order to leave comments, you need to log in
How to create a dictionary using dict?
I have two variables: x = 'one', y = 1
I want to create a dictionary with key x and value y using the dict class. Other methods are of no interest.
Logically, I write the following:
x, y = 'one', 1
my_dict = dict(x, y)
Answer the question
In order to leave comments, you need to log in
dict() expects an Iterable, i.e. something like this should work:
x, y = 'one', 1
my_dict = dict([(x, y),])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question