how can i separate from this list?
text = [('good', 'Title meta tag contains no errors.'), ('good', 'Title relevancy to page content is good.'), ('good', 'Desc开发者_运维百科ription 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.')]
the question is how can i separate the list to
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.']
any answer ?
This should give you what you want:
result = [y for x in text for y in x]
Another alternative that you may find more readable is to use itertools.chain
:
from itertools import chain
result = list(chain(*text))
Take a look at this question, very nice solution:
- Making a flat list out of list of lists in Python
Something like this should work:
>>> a=[(1,2),(3,4),(5,6)]
>>> [i for sl in a for i in sl]
[1, 2, 3, 4, 5, 6]
精彩评论