Home > OS >  How to change list of list to a string
How to change list of list to a string

Time:08-12

I need to get:

'W1NaCl U1NaCl V1NaCl'

from:

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

How to get required output in pythonic way

CodePudding user response:

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

Which yields: W1NaCl U1NaCl V1NaCl

CodePudding user response:

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

  • Related