【发布时间】:2016-03-29 01:57:29
【问题描述】:
有没有更简单的方法将列表中的字符串项连接成单个字符串?我可以使用str.join() 函数吗?
例如这是输入['this','is','a','sentence'] 这是所需的输出this-is-a-sentence
sentence = ['this','is','a','sentence']
sent_str = ""
for i in sentence:
sent_str += str(i) + "-"
sent_str = sent_str[:-1]
print sent_str
【问题讨论】:
-
'-'.join(sentence)
标签: python string list concatenation