Is there any other way to do this:
>>> in_string = "Hello, world! how are you? Your oceans are pretty. Incomplete sentence"
>>> def sep_words(string_1):
"""Function which takes a string and returns a list of lists contining the words"""
list_1 = string_1.split()
list_output = []
list_temp = []
for i in list_1:
if ((i[-1] == '!') or (i[-1] == '?') or (i[-1] == '.')):
list_temp.append(i[:-1])
list_temp.append(i[-1:])
list_output.append(list_temp)
list_temp = []
else:
list_temp.append(i)
if list_temp == []:
pass
else:
list_output.append(list_temp)
print (list_output)
>>> sep_words(in_string)
[['Hello,', 'world', '!'], ['how', 'are', 'you', '?'], ['Your', 'oceans', 'are', 'pretty', '.'], ['Incomplete', 'sentence']]