I am trying to remove specific words from my string to have a clear output. Words are adding one by one in a loop:
text += ’ ’ + word
text looks like this for example:
start this is a sentence end
(need to remove start and end)
I am trying to remove specific words from my string to have a clear output. Words are adding one by one in a loop:
text += ’ ’ + word
text looks like this for example:
start this is a sentence end
(need to remove start and end)
If guess you can add
if word in ["start", "end"]:
continue
To skip the words you don’t want?
this could work but im generating the text so i need start and end as flags to understand it begins and ends. I want to remove them after i have a string like text = start this is a sentence end
so it will be more clear
If you’re doing this after the fact, you can use the regular python string builtin to replace a string with another: sentence.replace("start", "")
.
Or if you always want to remove the begining and end, you can do sentence[len("start"):-len("end")-1]
.
Your first suggestion replaces every occurrence in the string with “”.
thanks, second solutions worked well