title: Python list index out of range - finding local maxima
body: <p>I have a dataset and am trying to work out where there are peaks in the data; a data point with a higher value than the point before and after it.</p>
  
  <p>I have code which works for one dataset but now transferring it to another dataset brings up index out of range error for certain lines.</p>
  
  <p>The code I have is:</p>
  
  <pre><code>for line in file.readlines():
      peaks.append(0)
      line = line.split(',')
      time.append(float(line[0]))
      TP.append(float(line[3]))
      level.append(float(line[5]))
  
  
  for i in range(len(level)-1):
      i = i + 1
      if (level[i] &gt; level[i-1]) and (level[i] &gt; level[i+1]):
          peaks[i] = 1
          noPeaks = noPeaks +1
  
  print noPeaks
  </code></pre>
  
  <p>Yet for one line (so far) it says data is out of range - visually inspecting the data doesn't suggest this - the value is higher than the previous value but lower than the next so on a rising limb of the graph.</p>
  
  <p>Any help would be great!</p>