I wrote the code of returning the words in a string into a list. But the code is not appending the last word in the string. Here I tried to replicate the split() method for strings. What will be the corrected code?
def splitstring(s):
a = []
count = ''
for i in s:
if i == ' ':
a.append(count)
count = ''
else:
count += i
return a
# Input = 'Hello World'
# Expected output = ['Hello', 'World']
# Actual = ['Hello']