【发布时间】:2012-01-23 07:38:42
【问题描述】:
我正在进行一项 Python 作业,该作业需要将文本分隔、排序和打印为:
- 句子由
.分隔 - 短语
, - 然后打印
到目前为止我做了什么:
text = "what time of the day is it. i'm heading out to the ball park, with the kids, on this nice evening. are you willing to join me, on the walk to the park, tonight."
for i, phrase in enumerate(text.split(',')):
print('phrase #%d: %s' % (i+1,phrase)):
phrase #1: what time of the day is it. i'm heading out to the ball park
phrase #2: with the kids
phrase #3: on this nice evening. are you willing to join me
phrase #4: on the walk to the park
phrase #5: tonight.
我知道需要一个嵌套的 for 循环并尝试过:
for s, sentence in enumerate(text.split('.')):
for p, phrase in enumerate(text.split(',')):
print('sentence #%d:','phrase #%d: %s' %(s+1,p+1,len(sentence),phrase))
TypeError: not all arguments converted during string formatting
欢迎提供提示和/或简单示例。
【问题讨论】:
-
专有代词“I”拼写为“I”。提及自己时,请使用“我”。总是。
标签: python string list for-loop