I am writing a very simple function that, given a string as input, parses the string into sentences, reverses the words of each sentence, and returns the reversed sentences but in the given sentence order. I am struggling with the string.split()
and string.join()
built-in methods and am getting a TypeError when I run the following python program.
import string
def reverseSentences(str):
senList = str.split('.')
for i, item in enumerate(senList[:]):
senList[i] = string.join(item.split(' ').reverse(), ' ')
return string.join(senList, '.') + '.'
When I try to print a call to this function it gives me a generic TypeError. Thanks for enduring my n00bishness.