The error you are getting is due to the fact you are trying to set a list
as a dictionary key.
The following example will reproducer the same results:
>>> d = dict()
>>> d[['a', 'b']] = 123
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
d[['a', 'b']] = 123
TypeError: unhashable type: 'list'
Let say it would work, it wouldn't create the expected list you wish to get.
It would results with something like this:
{ ['a','b']: 2,
['c','d']: 2,
['a','b','c']: 3
}
In order to get the list you are wishing for you need to create a nested loop (native solution).
import inflect
p = inflect.engine()
l=[['a','b'],['c','d'],['a','b','c']]
new_list = list()
count = 1
already_used_labels = set()
# The nested loop...
for inner_list in l:
for label in inner_list:
if label in already_used_labels:
continue
new_list.append({'data': {'id': p.number_to_words(count), 'label': label}})
count += 1
already_used_labels.add(label)
This will results with:
[
{'data': {'id': 'one', 'label': 'a'}},
{'data': {'id': 'two', 'label': 'b'}},
{'data': {'id': 'three', 'label': 'c'}},
{'data': {'id': 'four', 'label': 'd'}}
]
P.S
For more information about how to convert integers into words (inflect package).