I have a general question about the syntax used in Python. I am very new to programming so this might seem like a noob question, but I'm using pythons nltk, and in that there is a command which appears as follows...
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)
Is anyone able to explain the logic behind the "w for w in word_tokens"? I have seen this in several forms, so can anyone break down what is happening here in the "X for X in X"?
Would just like some clarity on the concept used here, thanks in advance!