Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h2>Updated Solution:</h2> <p>From the comments below, the new solution is:</p> <pre><code>idx = argsort(A[:, 0:2], axis=0)[:,1] kidx = where(sum(A[idx,:][:-1,0:2]!=A[idx,:][1:,0:2], axis=1)==0)[0] kidx = unique(concatenate((kidx,kidx+1))) for n in arange(0,A.shape[0],1): if n not in kidx: print A[idx,:][n] &gt; [1 3 4 5 6 7] [3 3 3 3 3 3] [3 4 6 7 7 6] [456 6 5 343 435 5] </code></pre> <p><code>kidx</code> is a index list of the elements you <em>don't</em> want. This preserves rows where the first two inner elements do not match any other inner element. Since everything is done with indexing, it should be fast(ish), though it requires a sort on the first two elements. Note that original row order is not preserved, though I don't think this is a problem.</p> <h2>Old Solution:</h2> <p>If I understand it correctly, you simply want to filter out the results of a list of lists where the first element of each inner list is equal to the second element.</p> <p>With your input from your update <code>A=[[1,1,3,5,6,6],[1,1,4,4,5,6],[1,3,4,5,6,7],[3,4,6,7,7,6],[1,1,4,6,88,7],[3,3,3,3,3,3],[456,6,5,343,435,5]]</code>, the following line removes <code>A[0]</code>,<code>A[1]</code> and <code>A[4]</code>. <code>A[5]</code> is also removed since that seems to match your criteria. </p> <pre><code>[x for x in A if x[0]!=x[1]] </code></pre> <p>If you can use numpy, there is a really slick way of doing the above. Assume that <code>A</code> is an array, then</p> <pre><code>A[A[0,:] == A[1,:]] </code></pre> <p>Will pull out the same values. This is probably faster than the solution listed above if you want to loop over it.</p>
 

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