NLTK停词的 for循环趋于无穷大


import nltk as nt
txt="The latest version of Anaconda comes with Python 3.8. But sometimes you need to use an earlier release. With Anaconda, the preferred way to use a previous version of Python is to create a separate conda environment for each project."
word_tok=nt.word_tokenize(txt)
stopWords=nt.corpus.stopwords.words("english")
print(word_tok)
wordClear=[]
for i in word_tok: # infinity loop
if i not in stopWords:
word_tok.append(i)

有什么问题吗?

我看到的总是up形式但是我的项目是这个形式是无限循环但是

for i in word_tok:
print(i)

This for did not infinite loop.

import nltk as nt
txt="The latest version of Anaconda comes with Python 3.8. But sometimes you need to use an earlier release. With Anaconda, the preferred way to use a previous version of Python is to create a separate conda environment for each project."
word_tok=nt.word_tokenize(txt)
stopWords=nt.corpus.stopwords.words("english")
print(word_tok)
wordClear=[]
for i in word_tok: # infinity loop
if i not in stopWords:
# Do you wantthis?
wordClear.append(i)

您正在更新数组word_tok并动态添加新的i。所以它可能会一直增加,永远不会结束。

相关内容

  • 没有找到相关文章

最新更新