Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to join elements within an array of strings? [duplicate]

I have this array of strings that I have split element wise so I can do stuff to it. Now I want to return them back into a sentence.

my_array = (['T', 'e', 's', 't', ' ', 'w', 'o', 'r', 'd', 's', '!'])

Is there a way to join them togeter back into a sentence whilst keeping the formatting? Ideal output would be something similar to the following:

joined_array = (['Test Words!'])
like image 634
KGreen Avatar asked Mar 25 '26 12:03

KGreen


1 Answers

Try join:

my_array = (['T', 'e', 's', 't', ' ', 'w', 'o', 'r', 'd', 's', '!'])
joined_array = ''.join(my_array)

Which gives:

'Test words!'
like image 140
funie200 Avatar answered Mar 28 '26 02:03

funie200



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!