I want to split the words in a string but keeping symbols separately too.
s = "Hello world. This-is-foo! I love you"
the output should be
out: ["Hello", "world", ".", "This", "-", "is", "-", "foo", "!", "I", "love", "you"]
I tried:
re.split('(\W)', s)
But this is the output:
['Hello',
' ',
'world',
'.',
'',
' ',
'This',
'-',
'is',
'-',
'foo',
'!',
'',
' ',
'I',
' ',
'love',
' ',
'you']
As you can see the spaces are left there. How can I solve this?