I want to split my string in separate sentences. My code is below
import tensorflow as tf
import pandas as pd
text = 'My cat is a great cat, this is very nice, you are doing great job'
text = text.split(',')
Output:
['My cat is a great cat', ' this is very nice', ' you are doing great job']
But I want this output to be
['My cat is a great cat'] ['this is very nice'] ['you are doing great job']
is it possible??
Yes it's possible, we have answers already given above but to match exact expected output as mentioned above use below:
inputlist = "apple,banana,cherry"
print(*[[s] for s in inputlist.split(',')],end=" ")
output:
['apple'] ['banana'] ['cherry']
You just turn into a list of list with this
text = 'My cat is a great cat, this is very nice, you are doing great job'
text = [[x] for x in text.split(", ")]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With