[英]Remove sentences with a certain character prefix
我想刪除 $//$ 字符以及字符后面的句子。
sentence = "The weather forecast for today is mostly sunny $//$ The forecast $//$ for tomorrow will be rainy. The rest of the week..."
預計output:“今天的天氣預報大部分是晴天”
任何幫助將不勝感激
sentence.split("$//$")[0]
將完成這項工作
首先你需要使用.split 拆分句子
word.split("$//$")
那么什么時候拆分有2個部分,所以我們可以使用索引來分隔它。
我們應該使用 [0] 作為您想要的部分的第一個元素。
所以代碼是:
word.split("$//$")
print(word[0])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.