title: Python check if next element exist in list
body: <p>I'm doing some challenges with Python.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>def SimpleSymbols(str):
      letters = []
      results = []
  
      for i in range(len(str)):
          if str[i] != '=' and str[i] != '+':
              letters.append(str[i])
  
              if str[i-1] == '+' and str[i+1] == '+':
                  results.append(str[i])
  
      return len(letters) == len(results)
  </code></pre>
  
  <p><a href="https://repl.it/BH1s/1" rel="nofollow">https://repl.it/BH1s/1</a></p>
  
  <p>If I check for <code>print(SimpleSymbols('++d+===+c++=='))</code> everything goes well but if I check for <code>print(SimpleSymbols('++d+===+c++==+a'))</code></p>
  
  <p>I get this error:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):   File "python", line 15, in
       File "python", line 9, in SimpleSymbols IndexError: string
    index out of range</p>
  </blockquote>
  
  <p>Can someone explain me please why?</p>