Я работаю над назначением 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
Подсказка и / или простой пример приветствуются.