title: How to debug "IndexError: list index out of range"?
body: <p>I'm getting "IndexError: list index out of range" from </p>
  
  <pre><code>buffer.append(data[data_index])
  </code></pre>
  
  <p>My code is as below:</p>
  
  <pre><code>data_index = 0
  def generate_batch(batch_size, num_skips, skip_window):
    global data_index
    assert batch_size % num_skips == 0
    assert num_skips &lt;= 2 * skip_window
    batch = np.ndarray(shape=(batch_size), dtype=np.int32)
    labels = np.ndarray(shape=(batch_size, 1), dtype=np.int32)
    span = 2 * skip_window + 1  # [ skip_window target skip_window ]
    buffer = collections.deque(maxlen=span)
    for _ in range(span):
      buffer.append(data[data_index])
      data_index = (data_index + 1) % len(data)
  </code></pre>