简体   繁体   中英

how can i separate from this list?

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.')]

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:

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM