title: How can I avoid index out of range error with enumerating, while comparing each element to its neighbour?
body: <p>I have an array that I am looping over and I want to compare each element to the element next to it, and if it is larger say, then I want to do something with its index. It's clear to me that enumeration would help in this case; however I am running into an <code>'index out of range error'</code>:</p>
  <pre><code>array = [1,2,3,4]
  
  for index,i in enumerate(array): 
      if array[index]&gt;array[index+1]: 
          ... 
  </code></pre>
  <p>While I know there are other ways of doing this,
  is there a way I can make the above work with <code>enumerate</code>? I tried to do enumerate(array)-1 ; knowing this would not work. But anything of this sort that would fix the indexing error? Thanks</p>
  <p>I know we can easily do the above with simply using 'i' from the for loop, but just curious if I can manipulate enumeration here.</p>