2010-12-05 63 views
0
text = [('good', 'Title meta tag contains no errors.'), ('good', 'Title relevancy to page content is good.'), ('good', 'Description meta tag contains no errors.'), ('good', 'Description relevancy to page content is excellent.'), ('good', 'Keywords meta tag contains no errors.'), ('good', 'Keyword relevancy to page content is excellent.'), ('good', 'The Robots meta tag contains no errors.'), ('good', 'The Author meta tag contains no errors.'), ('good', 'The size of the web page.'), ('good', 'The web page load time.')] 

的問題是,我怎麼能在列表中我如何從這個列表中分離出來?

text = ['good', 'Title meta tag contains no errors.', 'good', 'Title relevancy to page content is good.', 'good', 'Description meta tag contains no errors.', 'good', 'Description relevancy to page content is excellent.', 'good', 'Keywords meta tag contains no errors.', 'good', 'Keyword relevancy to page content is excellent.', 'good', 'The Robots meta tag contains no errors.', 'good', 'The Author meta tag contains no errors.', 'good', 'The size of the web page.', 'good', 'The web page load time.'] 

任何回答分開?

回答

5

這應該給你想要的東西:

result = [y for x in text for y in x] 

,你可能會發現更可讀的另一種方法是使用itertools.chain

from itertools import chain 
result = list(chain(*text)) 
+0

哦,太感謝你了:) – 2010-12-05 17:00:23

1

這個問題,很不錯的解決方案來看看:

像這樣的東西應該工作:

>>> a=[(1,2),(3,4),(5,6)] 
>>> [i for sl in a for i in sl] 
[1, 2, 3, 4, 5, 6] 
+0

謝謝你,你也站了起來;) – 2010-12-05 17:04:46

相關問題