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>Just simpley use tuple and list indices. If you only want one value from one specfic place in a container, don't use a loop, just use indices.</p>

<pre><code>res = (tuplelist[0][3],'has_val', tuplelist[1][3])
</code></pre>

<p>Full program:</p>

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

print(res)
</code></pre>

<p>Explanation:</p>

<ul>
<li><code>(tuplelist[0][3]</code>: Begin a tuple by using <code>(</code>. from the first tuple in <code>tuplelist</code> get the last item in that tuple and insert it in our current tuple.</li>
<li><code>,'has_val',</code>: add the string 'has_val' to our tuple...</li>
<li><code>tuplelist[1][3])</code>: for the last element in the current tuple, get the last element in the second tuple in <code>tuplelist</code>, and end our tuple with a <code>)</code>.</li>
</ul>

python list python-3.x tuples