2024-04-20 02:26:42 发布
网友
我想从下面的例子中取“期望”这个词。在python中我将如何做到这一点。比如在单行注释的情况下要做什么,如下所示。我试过打印之类的文本.拆分(“”)[1]但它只在没有单行注释的情况下工作。你知道吗
text = /* */ The desired {word} /* */
一种方法是使用^{},它是ConcordanceIndex按偏移量查找周围的单词:
ConcordanceIndex
import nltk text = """/* */ The desired word /* */""" tokens = nltk.word_tokenize(text) c = nltk.ConcordanceIndex(tokens) print([tokens[offset - 1] for offset in c.offsets("word")])
打印['desired']。你知道吗
['desired']
一种方法是使用^{} ,它是
ConcordanceIndex
按偏移量查找周围的单词:打印
['desired']
。你知道吗相关问题 更多 >
编程相关推荐