In Python, I have the following list of maps:
[{'CN': 'SC',
'LB': 'g1k',
'SM': 'HG1'},
{'CN': 'SC',
'LB': 'g2k',
'SM': 'HG2'},
{'CN': 'SC',
'LB': 'g3k',
'SM': 'HG3'}]
and I would like to obtain a map like this:
{ 'CN' : 'SC',
'LB' : ['g1k', 'g2k', 'g3k'],
'SM' : ['HG1', 'HG2', 'HG3']
}
What is the most pythonic way to do this?
Thanks!
p.s. Further, I intend to convert the new structure of data to JSON in order to be displayed in a web page.
This isn’t quite the data structure you wanted, but it’s pretty close and would be easy to change over if you really needed to. (I haven’t shown it here though as I think that
sets are the way to go here instead oflists).To get back to lists:
Or even: