I am interested unpacking the values of dictionary that contains a list of values.
I need to combined all the values inside the dictionary for each key.
d1 = {
'A': ['col1', 'col2'],
'B': ['col3', 'col4'],
'C': ['col5', 'col6']
}
The output I want is
d2 = {
'A': ['col1', 'col2', '0 col3', '0 col4', '0 col5', '0 col6'],
'B': ['0 col1', '0 col2', 'col3', 'col4', '0 col5', '0 col6'],
'C' : ['0 col1', '0 col2', '0 col3', '0 col4', 'col5', 'col6']
}
d1 = {'A': ['col1', 'col2'], 'B': ['col3', 'col4'], 'C': ['col5', 'col6']}
c1 = [v for k, v in d1.items()]
d2 = {}
for k, v in d1.items():
for l in c1:
if l in v:
d2[k] = l
else:
d2[k] = ','.join(l)
How can I unpack all the values for each key, combine them and a static value needs to be added for values not listed to the key.