Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a list of strings into one string [duplicate]

I'm super new to any sort of programming, so forgive my ignorance for not knowing how to do something that seems so simple.

All I'd like to do is take any array of strings (call it name), let's say:

["John", "Charles", "Smith"]

and remove it from the list and turn it into a string:

John Charles Smith

I can't seem to get my head around this and couldn't find a similar post.

like image 567
cccg03 Avatar asked Mar 18 '16 22:03

cccg03


People also ask

How do I make a list of strings in one string?

You can concatenate a list of strings into a single string with the string method, join() . Call the join() method from 'String to insert' and pass [List of strings] . If you use an empty string '' , [List of strings] is simply concatenated, and if you use a comma , , it makes a comma-delimited string.

How do you convert a list of strings to one string in Java?

Using StringBufferCreate an empty String Buffer object. Traverse through the elements of the String array using loop. In the loop, append each element of the array to the StringBuffer object using the append() method. Finally convert the StringBuffer object to string using the toString() method.

Can you concatenate a list and a string in Python?

You can go from a list to a string in Python with the join() method. The common use case here is when you have an iterable—like a list—made up of strings, and you want to combine those strings into a single string.

How do I turn a list into a tuple?

Using the tuple() built-in function An iterable can be passed as an input to the tuple () function, which will convert it to a tuple object. If you want to convert a Python list to a tuple, you can use the tuple() function to pass the full list as an argument, and it will return the tuple data type as an output.


1 Answers

Just use:

" ".join(["John", "Charles", "Smith"])
like image 163
projetmbc Avatar answered Oct 03 '22 14:10

projetmbc