Answer the question
In order to leave comments, you need to log in
How to equate key and value?
Hello everyone
Tell me, who knows (may have come across) - how to equate a key to a value in a dictionary?
That is, for example, there is a dictionary a = {'one' : 'uno', 'two' : 'duo'}, you need to do one = uno, two = duo
Answer the question
In order to leave comments, you need to log in
Yes, just create a new dictionary with the desired elements. Iterate over the values in the original and add them to the new one as keys and values.b = {v : v for v in a.values()}
tsarevfs wrote you almost correctly (except that you need to go by keys, not by values)
But why you put 'c' as a key in your code is a mystery.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question