2017-03-22 5 views
0

こんにちは、私はPythonで使用されている構文についての一般的な質問があります。 NLTK、以下のように表示されるコマンドがあることに...Pythonで "[w for word_tokensの場合は..."とはどういう意味ですか?

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) 

はロジックを説明することができ、誰です、これはnoobの質問のように見えるかもしれませんが、私はニシキヘビを使用していますので、プログラミングに非常に新しいです"w for word_tokens"の後ろに? 私はこれをいくつかの形で見てきました。だから誰も "X for X in X"でここで何が起きているのか分かりませんか?

ここで使用されているコンセプトについては、あらかじめありがとうございます。

+0

これは、リスト内包表記です。これはかなり混乱しやすいテーマになる可能性があるので、これをgoogleにする必要があります.1つの答えで説明するのは難しいです。それは_機能_プログラミングパラダイムの「代表」です。 – ForceBru

答えて

1
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) 
関連する問題