title: list index out of range, python
body: <p>I get an Error <strong>list index out of range</strong> when I'm trying to split a big list in to an array with arrays in it.</p>
  
  <p>I have no idea why this is happening. </p>
  
  <p>the end result of this code should be an array with arrays in it. So that i later can call for example val[5] and get 10 values. </p>
  
  <p>I'm able to print <code>val</code> if the <code>print</code> statement is inside the <code>for</code> loop. And the code is working as it should. But if I move the <code>print</code> statement outside the <code>for</code> loop I get the <code>Index out of range error</code>. </p>
  
  <pre><code>import sys
  import numpy as np 
  from numpy import array, random, dot
  
  def vectorizeImages(filename):
      file_object = open(filename)
      lines = file_object.read().split()
  
      #array to save all values that is digets.
      strings = []
      values = []
      images = []
      val = []
      test=[]
  
      #loop that checks if the position in the list contains a digit.
      #If it does it will save the digit to the value-array.
      for i in lines:
          if i.isdigit():
              strings.append(i)
  
      #Converting all the strings to ints.
      strings = list(map(int, strings))
  
      #deviding every value in the array by 32
      for i in strings:
          a = i 
          values.append(a)
  
      #splits large list into smaller lists and ads a 1 
  
      for i in range(len(values)):
          a = []
          for j in range(400): 
              a.append(values[i*400+j]) #ERROR:list index out of range
          a.append(1)
          val.append(a)
  </code></pre>