I was wondering if there is a straightforward way to do the following:
Input string:
input = 'Hello'
Output string:
output = 'H,e,l,l,o'
I understand you can do list(input)
, but that returns a list and I wanted to get the string rather than the list.
Any suggestions?
In [1]: ','.join('Hello')
Out[1]: 'H,e,l,l,o'
This makes use of the fact that strings are iterable and yield the individual characters when iterated over.
outputstr = ','.join(inputstr)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With