什么是;[w代表w在word中“如果……”在Python中是什么意思?
我对Python中使用的语法有一个一般性的问题。我对编程非常陌生,所以这可能看起来像是一个noob问题,但我使用的是pythons nltk,其中有一个命令如下所示什么是;[w代表w在word中“如果……”在Python中是什么意思?,python,python-3.x,nltk,Python,Python 3.x,Nltk,我对Python中使用的语法有一个一般性的问题。我对编程非常陌生,所以这可能看起来像是一个noob问题,但我使用的是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
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)
有人能解释“w代表w”在word_标记中的逻辑吗?
我已经在几种形式中看到了这一点,所以有人能在“X中的X中的X”中分解这里发生的事情吗
我只是想澄清一下这里使用的概念,提前谢谢
filtered_sentence = [w for w in word_tokens if not w in stop_words]
相当于:
filtered_sentence = []
for w in word_tokens:
if not w in stopwords:
filtered_sentence.append(w)
这是一个列表理解。你应该用谷歌搜索它,因为它可能是一个相当混乱的主题,很难用一个单一的答案来解释。这是函数式编程范例的“代表”。