Home > OS >  Convert multiple string elements list to a list with single element split by comma using Python
Convert multiple string elements list to a list with single element split by comma using Python

Time:12-17

I have a list with string elements: lst = ['h', 'e', 'l', 'l', 'o'], and I want to convert it to a single element list but split by ,.

The expected list will like this:

['h, e, l, l, o']

How could I do that?

CodePudding user response:

You could use a string join:

lst = ['h', 'e', 'l', 'l', 'o']
output = [', '.join(lst)]
print(output)  # ['h, e, l, l, o']
  • Related