If a user inputs a string "Hello world"
how can i get an output list to look like ["Hello", "world"]
instead of ['H','e','l','l','o',' ','w','o','r','l','d']
Whats an efficient way to do this?
I used a for loop, and omitted the whitespace but my output does not include the last character
def reverse_string(x):
reversed_list= []
temp_string = ""
count= 0
for i in x:
if i == " " or i == x[-1]:
reversed_list.insert(count, temp_string)
temp_string = ""
count+=1
continue
temp_string += i
my output: ['Hello', 'worl']
sorry if this is a repost