开发者

splitting and concatenating a string

开发者 https://www.devze.com 2023-03-21 09:54 出处:网络
I was wondering if python had a built in function similar to string->list and list->string in scheme.

I was wondering if python had a built in function similar to

string->list

and list->string in scheme.

开发者_如何学C

So for example I would like to turn 'abc' into ['a','b','c'] and vice versa using a built in function.


String to list:

>>> list('abc')
['a', 'b', 'c']

List to string:

>>> ''.join(['a', 'b', 'c'])
'abc'


Split using a list comprehension [c for c in theString] .. and join them again using ''.join(theList). Other ways exist.

0

精彩评论

暂无评论...
验证码 换一张
取 消