EN:
Hey, I have to write a function which tokenizes the Input "sentence".
Currently I do that with:
This code works fine.
But now I have to make sure that punctuation (. , : etc.) gets treated like a part of the strings so that e.g.:
sentence = "Hi, Ich bins."
is NOT just:
["Hi," "Ich", "bins."] (like it would be with .split() )
but that the output is:
["Hi", ",", "Ich", "bins", "."]
How can I get to that?
Apparently I need to use a for-loop for it, but I have no clue how.
(i cannot use NLTK or regex)
DE:
Hey, I have to write a function which tokenizes the Input "sentence".
Currently I do that with:
Code:
x = sentence.split()
But now I have to make sure that punctuation (. , : etc.) gets treated like a part of the strings so that e.g.:
sentence = "Hi, Ich bins."
is NOT just:
["Hi," "Ich", "bins."] (like it would be with .split() )
but that the output is:
["Hi", ",", "Ich", "bins", "."]
How can I get to that?
Apparently I need to use a for-loop for it, but I have no clue how.
(i cannot use NLTK or regex)
DE: