title: Detect condition between pairs of entries on a Python list
body: <p>Let's say I've a list:</p>
  
  <pre><code>ls = [1,2,4,3,6,18,10,60,70,40]
  </code></pre>
  
  <p>that I want to change to:</p>
  
  <pre><code>ls = [1,2,4,3,6,18,10,None,None,40]
  </code></pre>
  
  <p><strong>because:</strong></p>
  
  <hr>
  
  <p>1) There is a value in index "x+1" that is <strong>greater than 5 times</strong> than the value in index "x".</p>
  
  <p>(<strong>index 7: 60</strong>, is bigger than <strong>index 6: 10</strong> multiplied by <strong>5</strong>)</p>
  
  <hr>
  
  <p>2) The next value in index "x+2" is <strong>also greater than 5 times</strong> than the value in index "x" </p>
  
  <p>(<strong>index 8: 70</strong>, is bigger than <strong>index 6: 10</strong> multiplied by <strong>5</strong>)</p>
  
  <hr>
  
  <p>3) The value in index "x+3" <strong>isn't greater</strong> than the value in index "x" </p>
  
  <p>(<strong>index 9: 40</strong>, isn't bigger than <strong>index 6: 10</strong> multiplied by <strong>5</strong>)</p>
  
  <hr>
  
  <p>4) The two values of the indexes <strong>between the right condition</strong> ("x+1" and "x+2") will be <strong>replaced by None</strong> between the two "limits" ("x" and "x+3") that matched the condition, thus <strong>setting "x+1" and "x+2" as None</strong>. </p>
  
  <p>Note that the condition now is not between two consecutive indexes...</p>
  
  <hr>
  
  <h2>Edited with example code:</h2>
  
  <p>This is what i've tried, although it seems "too much"...</p>
  
  <pre><code>ls = [1,2,4,3,6,18,10,60,70,40]
  
  for i in range (1,len(ls)-1):   
      if ls[i-1] == None:
          # another for to get previous results????
          for o in range(0,i):
              if ls[o] != None:
                  lastGood = ls[o]
      else:
          if ls[i] &gt; ls[i-1]*5:
              ls[i] = None
          else:
              lastGood = ls[i-1]
  
          if ls[i] &lt; ls[i-1]/5:
              ls[i] = None
          else:
              lastGood = ls[i-1]
  
  
  
      if ls[i] &gt; lastGood*5:
          ls[i] = None
  
      if ls[i] &lt; lastGood/5:
          ls[i] = None
  
  
  
  print ls
  </code></pre>
  
  <p>--</p>
  
  <pre><code>output: [1, 2, 4, 3, 6, 18, 10, None, None, 40]
  </code></pre>
  
  <p>Thanks in advance!</p>