Trying to create multikey dictionary with values from the list, where keys of the dictionary are first column and first row values, except the empty cells.
The code below doesn't return the expected result. I also tried with map function and list comprehension.
# list data
list_data = [['', '', 'VARIANT1', 'VARIANT2'],
['power', 'kW', '12', '20'],
['range', 'm', '200', '400'],
['colour', '', 'blue', 'yellow']]
# my code
import collections
dict_data = collections.defaultdict()
for row in range(1: len(list_data)):
for column in range(2: len(list_data[0])):
dict_data[(list_data[row][0], list_data[0][column])
] = list_data[row][column]
# desired output
dict_data = {('power', 'VARIANT1'): '12',
('range', 'VARIANT1'): '200',
('colour', 'VARIANT1'): 'blue',
('power', 'VARIANT2'): '20',
('range', 'VARIANT2'): '400',
('colour', 'VARIANT2'): 'yellow', }