2016-09-18 95 views
-1

我知道如何将此列表更改为字符串,但我不知道如何使第一个和最后一个是| - 和 - |分别。从逻辑上看,S.join将一起加入名单,但在之后和之前不会改变,所以对于如何改变它们的任何建议都会很好。将列表更改为字符串

index = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] 

newindex = "-|-".join(index) 

>>>> 0-|-1-|-2-|-3-|-4-|-5-|-6-|-7-|-8-|-9 

我的预期输出是:

|-0-|-1-|-2-|-3-|-4-|-5-|-6-|-7-|-8-|-9-| 
+0

什么是您预期的输出?您需要提供[MCVE]。 –

+2

'''.join(index).replace('','| - ')'是否提供了所需的输出? –

+0

@JonClements不,我上面的''| |“。join(index)'比你的更接近。 –

回答

0

你可以尝试格式化

"|-{}-|".format("-|-".join(index))