简短的解决方案:
>>> l
['Kevin', 'went', 'to', 'his', 'computer.', 'He', 'sat', 'down.', 'He', 'fell', 'asleep.']
>>> print ' '.join(l)
Kevin went to his computer. He sat down. He fell asleep.
>>> print ' '.join(l).replace('. ', '.\n')
Kevin went to his computer.
He sat down.
He fell asleep.
长期的解决方案,如果你想确保在单词的两端只有时间触发换行符:
>>> l
['Mr. Smith', 'went', 'to', 'his', 'computer.', 'He', 'sat', 'down.', 'He', 'fell', 'asleep.']
>>> def sentences(words):
... sentence = []
...
... for word in words:
... sentence.append(word)
...
... if word.endswith('.'):
... yield sentence
... sentence = []
...
... if sentence:
... yield sentence
...
>>> print '\n'.join(' '.join(s) for s in sentences(l))
Mr. Smith went to his computer.
He sat down.
He fell asleep.