I'm trying to replicate the .split() string method. It works well but it doesn't include the last word.
def stringSplitter(string):
words = []
current_word = ""
for x in range(len(string)): #problem is here
if string[x] == " ":
words.append(current_word)
current_word = ""
else:
current_word += string[x]
return words
Test 1: When sentence=I like to ride my bicycle, my code incorrectly outputs:
['I', 'like', 'to', 'ride', 'my']
The result I want is:
['I', 'like', 'to', 'ride', 'my', 'bicycle']