用Python创建一个长英文字符串,给出字符串中的单词(应删除标点符号)组成的列表,计算单词总数量
时间: 2024-05-05 22:17:13 浏览: 108
可以使用以下代码创建长英文字符串,给出单词列表并计算单词总数量:
```python
import string
# 创建长英文字符串
long_string = """In the beginning God created the heavens and the earth. Now the earth was formless and empty, darkness was over the surface of the deep, and the Spirit of God was hovering over the waters."""
# 删除标点符号
translator = str.maketrans('', '', string.punctuation)
long_string = long_string.translate(translator)
# 给出单词列表
word_list = long_string.split()
# 计算单词总数量
word_count = len(word_list)
print(word_list)
print(word_count)
```
输出为:
```
['In', 'the', 'beginning', 'God', 'created', 'the', 'heavens', 'and', 'the', 'earth', 'Now', 'the', 'earth', 'was', 'formless', 'and', 'empty', 'darkness', 'was', 'over', 'the', 'surface', 'of', 'the', 'deep', 'and', 'the', 'Spirit', 'of', 'God', 'was', 'hovering', 'over', 'the', 'waters']
35
```
阅读全文