Note that there are some explanatory texts on larger screens.

plurals
  1. POmerging list of lists
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/13808774/i-want-to-group-tuples-based-on-similar-attributes">I want to group tuples based on similar attributes</a> </p> </blockquote> <p>I am very new to Python and coding in general, have a list of cluster pairs like so </p> <pre><code>[[1,2],[3,4],[2,3],[4,5]......], </code></pre> <p>I have written this code to join the cluster pairs into list of larger clusters.</p> <pre><code>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 </code></pre> <p>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?</p> <pre><code>[[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]] </code></pre> <p>Sorry, problem only happens when i have a fairly large number of pairs. And this is what I get </p> <pre><code>[[0, 9, 2, 13], [11, 1, 10, 3, 6], [3, 6], [4, 5, 7, 8, 12, 14]] </code></pre> <p>so the 3,6 there should have been merged but it hasn't. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload