If first 6 characters in list are the same then add a number in sequence?

People can probably make this alot more efficient than I did now just on a whim, but I wrote a python script into which you can put a set of strings, and get them out like you wanted, in sequence 0 to what ever.

Note: if you want the numbering to be 001 or 0001 and so on, just change the value in “zfill( )” in the code to the amount of integers you want to show.

Also note: Unique values in this script will not get an index number. If you want all values to get indexed, just change the “if count > 1:” into “if count > 0:” and you will get all values indexed.

image

This is the code you put into the script

OUT = []
initstrings = []
indices = []
count = 0
outputstring = IN[0]


for string in IN[0]:
	initstrings.append(len(string))
	
for i in range(0, len(IN[0])):
	currentstring = IN[0][i]
	if not len(outputstring[i]) > initstrings[i]:
		for string in range(0, len(IN[0])):
			if currentstring == IN[0][string]:
				count += 1
				indices.append(string)
	if count > 1:
		x = 0
		for i in indices:
			outputstring[i] = IN[0][i]+"."+str(x).zfill(2)
			x += 1
		x = 0
	count = 0
	indices = []

OUT = outputstring
2 Likes