I have somewhat resolved this issue and I'm just trying to figure out a more efficient way of doing this. I have a big list of lists and I am trying to compare each list in the big list with one another.
How can I avoid duplicate comparisons, comparing lists that have already been compared?
Ex: big_list[0] has been compared with big_list[20] so there is no reason to compare big_list[20] with big_list[0] later on in the loop.
big_list= [[0.12, 0.939, -0.321, 6.342], [0.12, 0.939, -0.321,6.342], [0.0, 1.0, -0.0, -5.166], [0.0, 1.0, 0.0, -5.166], [0.0, 1.0, -0.0, -5.166], [-0.0, 1.0, 0.0, -5.166], [0.0, 1.0, 0.0, -5.166], [0.0, 1.0, 0.0, -5.166], [0.0,1.0, -0.0, -5.166], [0.0, 1.0, 0.0, -5.166], [-0.0, 1.0, -0.0, -5.166], [-0.0, 1.0, 0.0, -5.166], [-0.12, 0.939, 0.321, 0.282], [-0.12, 0.939, 0.321, 0.282], [0.12, 0.939, 0.321, -17.782], [0.12, 0.939, 0.321, -17.782], [-0.0, 1.0, 0.0, 0.834], [0.0, 1.0, 0.0, 0.834], [0.0, 1.0, 0.0, 0.834], [0.0, 1.0, 0.0, 0.834], [-0.12, 0.939, -0.321, 24.406], [-0.12, 0.939, -0.321, 24.406], [0.0, 0.874, -0.486, 21.883], [0.0, 0.874, -0.486, 21.883], [0.0, 0.874, 0.486, -14.598], [0.0, 0.874, 0.486, -14.598]]
for j in range(len(big_list)):
for k in range(len(big_list)):
if j!=k:
result=math.sqrt(sum([(a-b)**2 for a,b in zip(big_list[j],big_list[k])])))
Previously, I resolved the matter by setting a specific tolerance and appending each result to a new list but I am trying to come up with a more efficient way of doing this. Eventually, big_list will probably have 1 million+ lists
if result<=rel_tol and big_list[k] not in new_list:
new_list.append(big_list[k])