-2

I´m trying to convert the values inside a dictionary to be in a list (for future upload in mySQL).

So currently I have the dictionary like below:

old_dict = {'key1':'value1','key2':value2,'key3':'value3'}

And I´m looking for something like:

new_dict = {'key1':['value1'],'key2':[value2],'key3':['value3']}
Lucas Mengual
  • 249
  • 3
  • 17

1 Answers1

1
new_dict = {k: [v] for k, v in old_dict.items()}
Thomas Grainger
  • 1,893
  • 24
  • 33