简体   繁体   中英

How to change list of list to a string

I need to get :

'W1NaCl U1NaCl V1NaCl'

from :

[['W1NaCl'], ['U1NaCl'], ['V1NaCl']]

How to get required output in pythonic way

You can do:

[[i] for i in 'W1NaCl U1NaCl V1NaCl'.split()]

Split will chop it into words, and the list comprehension will make the inner-arrays

items = [['W1NaCl'], ['U1NaCl'], ['V1NaCl']]
res = " ".join([item[0] for item in items])

Which yields: W1NaCl U1NaCl V1NaCl

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