Python evaluation of compound statement as if condition
<p>I'm have trouble understanding the evaluation order of statements that are if statement conditions:</p>

<p>assume I have a dictionary like this, that maps words to a list of webpages:</p>

<pre><code>index = { WORD, [url1,url2,url3] }
</code></pre>

<p>When inserting into this index there are two cases:</p>

<p>1) The key (WORD) does not exist in the index already, you need to create a list and set WORD as a<br>
key in the map</p>

<p>2) The key (WORD) exists in the index already, I just need to append the current url to the list already in the dictionary</p>

<p>What I expected to work:</p>

<pre><code>def update_index(word, url):
    if word in index and not(url in index[word]):
       index[word].append(url) # list already exists append to it
    else: 
       index[word] = [url] # new list with url as a single element
</code></pre>

<p>This however only every allows 1 url per word. </p>

<p>What did work:</p>

<pre><code>def update_index(word, url):
    if word in index:                  # &lt;- isnt having two consecutive if statements 
                                       # the same as an AND???
       if not(url in index[word]):
          index[word].append(url) # list already exists append to it
    else: 
       index[word] = [url] # new list with url as a single element
</code></pre>

<p>Any help clearing this up would be appreciated.</p>
