title: Comparing elements in a list with its neighbours
body: <p>I have a list of 29400 values in Python and I'm trying to check if each element of the list is larger than both the 2000 neighbors to its left and the 2000 neighbors to its right. If the element is larger than its 4000 neighbors, I want to retrieve the index of the element. If there aren't 2000 neighbors to the right I just want to compare it with future elements until I reach the end of the list, and vice versa if there aren't 2000 values to the left.</p>
  
  <pre><code>def find_peaks(t):
  prev = []
  future = []
  peak_index = []
  for i in range(len(t)-2000): # compare element with previous values
      for j in range(1,2001):
          if t[i]&lt;t[i+j]:
              prev.append(False)
              break
          if j==2000:
              if t[i]&lt;t[i+j]:
                  prev.append(False)
                  break
              prev.append(True)
  
  for i in range(1999,len(t)-1): # compare element with future values
      for j in range(1,2001):
          if t[i]&lt;t[i-j]:
              future.append(False)
              break
          if j==2000:
              if t[i]&lt;t[i-j]:
                  future.append(False)
                  break
              future.append(True)
  future = future[::-1] # reverse list
  for i in range(0,len(prev)-1):
      if prev[i] == True:
          if prev[i] == True:
              peak_index.append(i)
  </code></pre>
  
  <p>Does anyone know of any better ways to go about this? I was having trouble comparing elements near the end and the beginning of the list- If there aren't 2000 elements left in the list for me to compare with, then the list wraps around to the beginning of the list, which isn't something I want.</p>