Build a single list of element from bi-dimensional array list
<p>I'm totally noob to python so please forgive my mistake and lack of vocabulary. Long Story Short, I have the following list of array :</p>

<pre><code>[url1, data1][url2, data2][url3, data3]etc...
</code></pre>

<p>I want to build a simple list of element by only keeping the url. So I'm doing this :</p>

<pre><code>  if results:
    for row in results.get('rows'):
      data.append(row[:1])
    print data
</code></pre>

<p>for this result:</p>

<pre><code>[[url1][url2][url3]etc...]
</code></pre>

<p>However I would like to have something like this :</p>

<pre><code>[[url1, url2, url3,etc...]
</code></pre>

<p>I've imported numpy and tried this but doesn't work :</p>

<pre><code>np.array(data).tolist()
</code></pre>

<p>Any help ?  </p>

<p>thanks.</p>

<p>If you just want the <code>url</code>, and your data is basically a list of lists then you can just use the <code>index</code> number, in this case <code>[0]</code> as url is the 1st element in a nested list</p>

<pre><code>l = [['url1', 'data1'],['url2', 'data2'],['url3', 'data3']]
endlist = []
for i in l:
    endlist.append(i[0])

print endlist
</code></pre>

<p>Output:</p>

<pre><code>['url1', 'url2', 'url3']
</code></pre>

<p>However, make sure how your data is structured. A list of lists looks like <code>[[],[],[]]</code>, where each nested list is seperated by a <code>,</code> (comma) which is absent in the example you posted. </p>

python arrays