首页 > 解决方案 > 如何在Python列表中的每个元素后插入空格

问题描述

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

['mathematician', 'to', 'present', 'a', 'proof', 'of', 'the', 'sensitivity']

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

decrypted_word = ''.join(decrypted_characters)

当我打印时它看起来像

数学家提出敏感性证明

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

数学家提出敏感性证明

谢谢!

标签: python-3.xlist

解决方案


使用join

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

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


推荐阅读