Possible Duplicate:
I want to group tuples based on similar attributes
I am very new to Python and coding in general, have a list of cluster pairs like so
[[1,2],[3,4],[2,3],[4,5]......],
I have written this code to join the cluster pairs into list of larger clusters.
for i in range (len(Clist)):
for j in range(i+1,len(Clist)):
for disk in Clist[i]:
if disk in Clist[j]:
joined=joincluster(Clist[i], Clist[j])
Clist[i]=list(set(joined))
Clist[j]=[]
break
I go on to take the empty ones out. However it doesn't join all the pairs up when i have more then 30 or so cluster pairs, some clusters that should have been joined have not been. I can't see where I'm going wrong? Can anybody me identify the problem?
[[0, 2], [0, 9], [1, 10], [2, 0], [2, 9], [3, 6], [3, 10], [3, 11], [4, 5], [4, 7], [4, 12], [4, 14], [5, 4], [5, 8], [5, 12], [5, 14], [6, 3], [6, 10], [6, 11], [7, 4], [7, 12], [8, 5], [8, 14], [9, 0], [9, 2], [9, 13], [10, 1], [10, 3], [10, 6], [10, 11], [11, 3], [11, 6], [11, 10], [12, 4], [12, 5], [12, 7], [13, 9], [14, 4], [14, 5], [14, 8]]
Sorry, problem only happens when i have a fairly large number of pairs. And this is what I get
[[0, 9, 2, 13], [11, 1, 10, 3, 6], [3, 6], [4, 5, 7, 8, 12, 14]]
so the 3,6 there should have been merged but it hasn't.