extracting tuple values from list of tuples
<p>I have a list containg tuples of different types like:</p>

<pre><code>[(0, 1, 'BLANK', ''), (0, 2, 'PERSON', 'Deraj'), (3, 8, 'DOB', 'April 27 , 1834'), (9, 11, 'PERSON', 'David Deraj'), (11, 13, 'LOC', 'Pennsylvania'), (16, 19, 'PERSON', 'Mary Deraj')]
</code></pre>

<p>How do i get the following output</p>

<pre><code>('Deraj', 'David Deraj')
('Deraj', 'Mary Deraj')
</code></pre>

<p>i am trying to use for loop:</p>

<pre><code>for i in l:
    if i[2] == 'PERSON':
        m = list(i[3])
</code></pre>

<p>but this doesnt work.</p>

<p>Assuming that the first record <code>(0, 2, 'PERSON', 'Deraj')</code> has always the first item zero and the second item indicating the number of family members, you can do this in one line.</p>

<pre><code>print [ (entry[3].split()[1], entry[3])
        for entry in data
        if (entry[2] == 'PERSON' and entry[0] &gt; 0) ]
</code></pre>

python list python-3.x tuples