如何在Python列表中的每个元素之后插入空格

时间:2019-09-15 23:19:15

标签: python-3.x list

我有一个看起来像这样的列表'decrypted_characters'

  

[“数学家”,“到”,“现在”,“一个”,“证明”,“ of”,“ the”,“敏感性”]

我希望它看起来像一个段落,所以我尝试了

decrypted_word = ''.join(decrypted_characters)

当我打印时,它看起来像

  

数学家表示敏感性的证明

如何在每个元素后添加空格,使其看起来像句子?我希望它看起来像

  

数学家提出敏感性证明

谢谢!

2 个答案:

答案 0 :(得分:0)

使用join

In [4]: ' '.join(['mathematician', 'to', 'present', 'a', 'proof', 'of', 'the', 'sensitivity'])

Out[4]: 'mathematician to present a proof of the sensitivity'

答案 1 :(得分:0)

decrypted_characters = ['mathematician', 'to', 'present', 'a', 'proof', 'of', 'the', 'sensitivity']
decrypted_word = ' '.join(decrypted_characters)
print(decrypted_word)

尝试一下。