I have a list of strings. I want to assign a unique number to each string (the exact number is not important), and create a list of the same length using these numbers, in o
Since you are mapping strings to integers, that suggests using a dict. So you can do the following:
d = dict() counter = 0 for name in names: if name in d: continue d[name] = counter counter += 1 numbers = [d[name] for name in names]