title: Python: list index out of range when trying to compare two strings at index?
body: <p>I have this function to check if a string contains three or more lowercase letters.</p>
  
  <pre><code>def lowerCaseValid(word):
  lowCharList = ['abcdefghijklmnopqrstuvwxyz']
  i = 0
  flag = 0
  while i &lt;= len(word):
      j = 0
      while j &lt;= len(lowCharList):
          if lowCharList[j] == word[i]:
              flag += 1
              j = 0
          else:
              j += 1
      i += 1
  if flag &gt;= 3:
      return True
  </code></pre>
  
  <p>In simple terms, I pass in a string (word) and create a list of acceptable characters (lowCharList). </p>
  
  <p>Then, I set up a nested while loop that checks word[i] at every index of lowCharList, until it finds a match. </p>
  
  <p>Then it resets lowCharList counter and adds 1 to flag, and moves on to word[i+1]. </p>
  
  <p>If it doesn't find a match by the time it reaches z, then it moves onto word[i+1] anyways.</p>
  
  <p>For some reason, why I try my sample input in my main function.</p>
  
  <pre><code>def main():
    word = 'corRe!33'
    print(lowerCaseValid(word))
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>in lowerCaseValid
  if lowCharList[j] == word[i]:
  IndexError: list index out of range
  </code></pre>
  
  <p>Why is it throwing this error? Thank you.</p>