I have a list of tuples, like so:
lst_of_tpls = [(1, 'test2', 3, 4),(11, 'test12', 13, 14),(21, 'test22', 23,24)]
And I would like to convert it to a dictionary so that it looks like this:
mykeys = ['ones', 'text', 'threes', 'fours']
mydict = {'ones': [1,11,21], 'text':['test2','test12','test22'],
'threes': [3,13,23], 'fours':[4,14,24]}
I have tried to enumerate the lst_of_tpls
like so:
mydict = dict.fromkeys(mykeys, [])
for count, (ones, text, threes, fours) in enumerate(lst_of_tpls):
mydict['ones'].append(ones)
but this puts the values I would like to see in 'ones' also in the other "categories":
{'ones': [1, 11, 21], 'text': [1, 11, 21], 'threes': [1, 11, 21], 'fours': [1, 11, 21]}
Also, I would like to keep mykeys
flexible.