How to retain position values of original list after the elements of the list have been sorted into pairs (Python)?
<pre><code>sample = ['AAAA','CGCG','TTTT','AT$T','ACAC','ATGC','AATA']
Position = [0,    1,     2,     3,      4,     5,     6]
</code></pre>

<p>I have the above sample with positions associated with each element. I do several steps of filtering, the code of which is given <a href="https://eval.in/662091" rel="nofollow">here.</a></p>

<p>The steps in the elimination are:</p>

<pre><code>#If each base is identical to itself eliminate those elements eg. AAAA, TTTT
#If there are more than 2 types of bases (i.e.' conversions'== 1 ) then eliminate those elements eg. ATGC
#Make pairs of all remaining combinations
#If a $ in the pair, then the corresponding base from the other pair is eliminated eg. (CGCG,AT$T) ==&gt; (CGG, ATT) and (ATT, AAA)
#Remove all pairs where one of the elements has all identical bases eg. (ATT,AAA)
</code></pre>

<p>In the end, I have an output with different combinations of the above as shown below.</p>

<pre><code>Final Output [['CGG','ATT'],['CGCG','ACAC'],['CGCG','AATA'],['ATT','ACC']]
</code></pre>

<p>I need to find a way such that I get the positions of these pairs with respect to the original sample as below. </p>

<pre><code>Position = [[1,3],[1,4],[1,6],[3,4]]
</code></pre>

<p>You could convert the list to a list of tuples first</p>

<pre><code>xs = ['AAAA', 'CGCG', 'TTTT', 'AT$T', 'ACAC', 'ATGC', 'AATA']
ys = [(i, x) for i,x in enumerate(xs)]

print(ys)
=&gt; [(0, 'AAAA'), (1, 'CGCG'), (2, 'TTTT'), (3, 'AT$T'), (4, 'ACAC'), (5, 'ATGC'), (6, 'AATA')]
</code></pre>

<p>Then work with that as your input list instead</p>

python list indexing position