I try to find positions in list - data[i][2] if the string equal with the others string values, but if there are more than two of the same values, I do not want duplicates. And then I want to sort list. I need to keep the position of the first wanted for sort.
Thanks for help.
INPUT:
data = [["something1", 1, "number one", "inf 1",1, 33,22, "other"],
["something2",2, "number twenty", "inf 2", 1,66, 11, "other"],
["something3",3, "number one", "inf 3", 1,99, 55, "other"],
["something4",4, "number five", "inf 4", 1, 1212, 9988, "other"],
["something5",3, "number four", "inf 3", 1,99, 55, "other"],
["something6",3, "number one", "inf 3", 1,99, 55, "other"],
["something7",3, "number twenty", "inf 3", 1,99, 55, "other"]]
listMatch = []
for i in range(len(data)):
for j in range(i+1, len(data)-1):
if data[i][2] in data[j+1][2]:
if len(listMatch) == 0:
listMatch.append([i, j+1])
if len(listMatch) > 0:
if ([i, j+1]) not in listMatch:
listMatch.append([i, j+1])
#print(data[i][2],(i, "Position of search value"), (j+1, "Position of found value"))
print(listMatch)
OUTPUT:
[[0, 2], [0, 5], [1, 6], [2, 5]]
GOAL 1:
[[0, 2], [0, 5], [1, 6]]
GOAL 2:
data = [["something1", 1, "number one", "inf 1",1, 33,22, "other"],
["something3",3, "number one", "inf 3", 1,99, 55, "other"],
["something6",3, "number one", "inf 3", 1,99, 55, "other"],
["something2",2, "number twenty", "inf 2", 1,66, 11, "other"],
["something7",3, "number twenty", "inf 3", 1,99, 55, "other"],
["something4",4, "number five", "inf 4", 1, 1212, 9988, "other"],
["something5",3, "number four", "inf 3", 1,99, 55, "other"]]