labels = []
label2index = {}
outputlist = []
for group in input:
    current = []
for label in group:
    if label not in label2index:
        label2index[label] = len(labels)
labels.append(label)
current.append(label2index[label])
outputlist.append(current)
outputmapping = {}
for idx, val in enumerate(labels):
    outputmapping[idx] = val
efficient list mapping in python