relation between tuple values in a list according to their position
<p>Consider a list containing tuples like:</p>

<pre><code>tuplelist = [('a','b', 'c', 'd'), (6, 3, 9, 11), (0, 4, 5, 6)]
</code></pre>

<p>How can i match corresponding tuple positions.For ex for <code>'d'</code>:</p>

<pre><code>(d, 'has_val', 11)
(d, 'has_val', 6)
</code></pre>

<p>i have tried the following:</p>

<pre><code>str = 'has_val'
for i in tuplelist:
    rel = (i[3],str,i[3])
</code></pre>

<p>but this doesn't give me the desired output</p>

<p>zip() can work for your problem</p>

<pre><code>tuplelist = [('a','b', 'c', 'd'), (6, 3, 9, 11), (0, 4, 5, 6)]

tuplelist_withposition=zip(tuplelist[0],tuplelist[1],tuplelist[2])

s = 'has_val'
for i in tuplelist_withposition:
     rel = (i[0],s,i[1])
     print rel
     rel=(i[0],s,i[2])
     print rel
</code></pre>

<p>output:</p>

<pre><code>('a', 'has_val', 6)
('a', 'has_val', 0)
('b', 'has_val', 3)
('b', 'has_val', 4)
('c', 'has_val', 9)
('c', 'has_val', 5)
('d', 'has_val', 11)
('d', 'has_val', 6)
</code></pre>

python list python-3.x tuples