【发布时间】:2021-07-25 08:58:14
【问题描述】:
我想根据与列表重合的短语来拆分一个句子。 例如:
sentence = "the world is too big"
list = ["too big", "too small", "the world", "too many"]
如果句子中包含属于列表的词组,它想看到的分解结果是:
result = ["the world", "is", "too big"]
代替:
result = ["the", "world", "is", "too", "big"]
非常感谢
【问题讨论】:
-
只是一个旁注,永远不要使用
list这个词来定义变量,因为你正在用它来隐藏内置的list。dict、str、int等也是如此