title: Searching for an element in a list with a loop in Python
body: <p>I've been having some trouble finding if an element is already stored in a list in a Python code. I've used two scripts. The second one I wrote turned out to work, but the first one didn't and I don't understand why (and it's bothering me). The list I have is called <code>grains</code> and looks like this :<br>
  <code>[[a, b], [c, d], [e, f], ...]</code>.</p>
  
  <p>Here is the first piece of code, not working :</p>
  
  <pre><code>for i in range(0, len(grains) - 1) :
      if grains[i] == [x,y] :
          return
      else :
          grains.append([x,y])
          grains_restants = grains_restants - 1
          fourmi_chargee = False
          return
  </code></pre>
  
  <p>And here is the second piece of code, this one works :</p>
  
  <pre><code>if not([x,y] in grains) :
      grains.append([x,y])
      grains_restants = grains_restants - 1
      fourmi_chargee = False
      return
  </code></pre>
  
  <p>So I tried to understand why the first piece of code doesn't work, but I gave up. Do you know why ?</p>