如何在不添加任何字符的情况下将列表合并为字符串? [英] How to merge list to become string without adding any character in python?
本文介绍了如何在不添加任何字符的情况下将列表合并为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现我可以使用'-'.join(name)加入他们,但我不想添加任何字符.可以说我有
['stanje1', '|', 'st6', ',' 'stanje2', '|', '#']
我想成为这样
I found that I can join them with '-'.join(name) but I dont want to add any character. Lets say I have
['stanje1', '|', 'st6', ',' 'stanje2', '|', '#']
and I want to be like this
stanje1|st6,stanje2|#
推荐答案
在这种情况下,您可以这样做:
In that case, you can just do it as:
''.join(name)
>>> name = ['stanje1', '|', 'st6', ',' 'stanje2', '|', '#']
>>> print ''.join(name)
stanje1|st6,stanje2|#
这将连接没有中间字符串的字符串.
This will join the string with no intermediate string.
>>> s = ['Hello', 'World']
>>> print ''.join(s)
HelloWorld
>>> print '-'.join(s)
Hello-World
这篇关于如何在不添加任何字符的情况下将列表合并为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文