Home > Blockchain >  How to convert multiple string in one list python
How to convert multiple string in one list python

Time:09-21

I am wondering how to convert multiple string in a list into one string in a list?

It will be like this:

input:["a", "b", "c"]
output:["a,b,c"]

Thanks a lot!

CodePudding user response:

You can use join()

string = ["a", "b", "c"]
[','.join(string)] #if you want to return it inside a list otherwise
','.join(string)

CodePudding user response:

my_string = ["a", "b", "c"]
new_string = []
for s in my_string:
    new_string.append(s)

print (new_string)

output ['a', 'b', 'c']

CodePudding user response:

Create a new array, and then add it in a loop, append.

  • Related