Python 2.7 if not any syntax?
<p>I just read a brilliant reply from <a href="https://stackoverflow.com/users/142637/sloth">Sloth</a> at <a href="https://stackoverflow.com/questions/11968998/remove-lines-that-contain-certain-string">Remove lines that contain certain string</a> question whilst searching for a way to filter out garbage lines in a txt / csv file.  The gist is "take x y z words/strings/whatever from input file, then filter through each line writing only the unfiltered lines."</p>

<p>The code he posted was:</p>

<pre><code>bad_words = ['bad', 'naughty']

with open('oldfile.txt') as oldfile, open('newfile.txt', 'w') as newfile:
for line in oldfile:
    if not any(bad_word in line for bad_word in bad_words):
        newfile.write(line)
</code></pre>

<p>My question is:  Would someone explain the line <code>if not any(bad_word in line for bad_word in bad_words):</code> ?</p>

<p>I tried just putting in <code>if not any(bad_word in line):</code> but it gave me an error.  </p>

<p>I am trying to understand why.  A cursory search at python docs webpage didn't help me (I'm new to Python/programming and might not be too bright to boot :-) ).  </p>

<p>Any references for me to read is appreciated.</p>

<p>Thanks!</p>