Answer the question
In order to leave comments, you need to log in
I need to make the key value a dictionary, how to do it?
I have a dictionary
a = {'Spartacus': 2, 'Zenith': 2, 'Locomotive': 2} And I need to make each value a dictionary.
That is, it should turn out:
a = {'Spartacus': [2], ' Zenit': [2], 'Locomotive': [2]}
But new keys and values can be added to the dictionary
For example:
{'Spartak': 2, 'Zenith': 2, 'Locomotive': 2, 'CSKA': 2}
And I won't know for sure what these values and keys will be
Answer the question
In order to leave comments, you need to log in
Based on the above example:
a = {'Спартак': 2, 'Зенит': 2, 'Локомотив': 2}
for key in a:
a[key] = [a[key]]
print(a) # {'Спартак': [2], 'Зенит': [2], 'Локомотив': [2]}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question