title: Referencing list entries within a for loop without indexes, possible?
body: <p>A question of particular interest about python for loops. Engineering programs often require values at previous or future indexes, such as:</p>
  
  <pre><code>for i in range(0,n):
      value = 0.3*list[i-1] + 0.5*list[i] + 0.2*list[i+1]
  </code></pre>
  
  <p>etc...</p>
  
  <p>However I rather like the nice clean python syntax:</p>
  
  <pre><code>for item in list:
      #Do stuff with item in list
  </code></pre>
  
  <p>or for a list of 2d point data:</p>
  
  <pre><code>for [x,y] in list:
      #Process x, y data
  </code></pre>
  
  <p>I like the concept of looping over a list without explicitly using an index to reference the items in the list. I was wondering if there was a clean way to grab the previous or next item without looping over the index (or without keeping track of the index independently)?</p>
  
  <p>EDIT:</p>
  
  <p>Thanks Andrew Jaffe (and by proxy Mark Byers) and gnibbler for the simple, extendable examples. I wasn't aware of the itertools or nwise modules till now. John Machin - thanks for the very complex example of what NOT to do. You put a lot of effort into this example, obviously the somewhat recursive algorithm I presented cannot produce a list with the same number of elements as the input list and it presents problems if not using explicit indexes. An algorithm like this would commonly occur in signal processing.</p>