How to extract a string from a list
<p>I'm new to Python without any programming background except for some shell scripting.</p>

<p>I want to extract 2 fields from the below list: Here I want 'title' and 'plays' and assign it to a another list eg) new_list=[title,plays]</p>

<pre><code>alist=[(0, 'title', 'TEXT', 0, None, 0), (1, 'plays', 'integer', 0, None, 0)]
</code></pre>

<p>The simplest way, of course, it is just write the assignment statement:</p>

<pre><code>new_list=['title','plays']
</code></pre>

<p>But you probably intended to ask a more general question, like "How can I extract the 2nd item from the first two tuples in a list?" Like so:</p>

<pre><code>new_list = [alist[0][1], alist[1][1]]
</code></pre>

<p>Or maybe you meant, "How can I extract the 2nd item from each tuple in a list?" Like so:</p>

<pre><code>new_list = [t[1] for t in alist]
</code></pre>

python python-2.7 python-3.x