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>

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

<p>to check,</p>

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

<p><strong>Explain</strong></p>

<p>This line: </p>

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

<p>Above is actually a <code>tuple</code> inside <code>list</code>. So inside the the <code>alist</code>, there are two <code>tuples</code>. Inside each <code>tuple</code>, there are <code>6</code> <code>objects</code>.</p>

<p>So <code>alist[0]</code> means, you are calling the first <code>tuple</code> inside the <code>alist</code>.
and <code>alist[0][1]</code> means your are calling <code>second</code> element of the first <code>tuple</code>. Like this, you can think about <code>alist[1][1]</code> also.</p>

python python-2.7 python-3.x