Simon Breton Simon Breton - 4 months ago 20
Python Question

Build a single list of element from bi-dimensional array list

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 :

[url1, data1][url2, data2][url3, data3]etc...

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

if results:
for row in results.get('rows'):
print data

for this result:


However I would like to have something like this :

[[url1, url2, url3,etc...]

I've imported numpy and tried this but doesn't work :


Any help ?



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

l = [['url1', 'data1'],['url2', 'data2'],['url3', 'data3']]
endlist = []
for i in l:

print endlist


['url1', 'url2', 'url3']

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