def create_lookup_list(messages, labels):
    lookup = collections.defaultdict(set)
for msg in messages:
    for l, v in zip(labels, msg):
        lookup[l].add(v)
for k, v in list(lookup.items()):
    lookup[k] = list(v)
lookup_list = []
for msg in messages:
    lookup_list.append([lookup[l].index(v) for l, v in zip(labels, msg)])
return lookup_list, lookup
Convert list of objects to a list of integers and a lookup table