title: Python while loop string index out of range
body: <p>I am looping a string in Python to append in a list the words between &quot;;&quot; (I know there are other ways to loop strings in Python but I want this to work):</p>
  <pre><code>data = &quot;ABC;AB;AB&quot;
  data_len = len(data)
  items = []
  separator = &quot;;&quot;
  
  i = 0
  while i &lt; data_len:
      item = ''
      if i == 0:
          while data[i] != separator:
              item += data[i]
              i += 1
          items.append(item)
          continue
      i += 1
      while data[i] != separator and i &lt; data_len:
          item += data[i]
          i += 1
                      
      items.append(item)
  </code></pre>
  <p>The logic seems correct to me but somehow the interpreter throws an Index out of range exception:</p>
  <blockquote>
  <p>while data[i] != separator and i &lt; data_len: IndexError: string index
  out of range</p>
  </blockquote>