我有一个关于 Python 中使用的语法的一般性问题。我对编程非常陌生,所以这可能看起来像是一个菜鸟问题,但我正在使用 pythons nltk,并且其中有一个命令如下所示......
word_tokens = word_tokenize(example_sent)
filtered_sentence = [w for w in word_tokens if not w in stop_words]
filtered_sentence = []
for w in word_tokens:
if w not in stop_words:
filtered_sentence.append(w)
Run Code Online (Sandbox Code Playgroud)
有谁能够解释“w for w in word_tokens”背后的逻辑吗?我已经以多种形式看到了这一点,所以有人能分解一下“X for X in X”中发生的事情吗?
只是想澄清这里使用的概念,提前致谢!