title: When I list the integers in a list, an extra one gets added at the end [Python]
body: <pre><code>numberlist = [1, 4, 7, 5, 6, 2, 4]
  
  for i in numberlist:
      pos = numberlist.index(i)
      next = pos + 1
      ordering = [i, numberlist[next]]
      print(ordering)
  </code></pre>
  <p>This is the code I'm having problems with. When I run it, it's supposed to print multiple lists containing 2 items: The value of i and the number right after it. It does that, however an extra number is added for the last iteration and there is no consistency of what number it may be, in this case the output is:</p>
  <pre><code>[1, 4]
  [4, 7]
  [7, 5]
  [5, 6]
  [6, 2]
  [2, 4]
  [4, 7]
  </code></pre>
  <p>A 7 is added at the end, and while I thought it may have been just a repetition of a number that is already in the list, if I add another value to the list,</p>
  <pre><code>numberlist = [1, 4, 7, 5, 6, 2, 4, 6]
  </code></pre>
  <p>The output becomes:</p>
  <pre><code>[1, 4]
  [4, 7]
  [7, 5]
  [5, 6]
  [6, 2]
  [2, 4]
  [4, 7]
  [6, 2]
  </code></pre>
  <p>A 2 is added, but 2 isn't present in the list to begin with, and I also noticed that the 6 isn't taken into consideration, it prints the 7 again. However, if instead of a 6, I added a 3, the code would just give me an error, as it should.</p>
  <pre><code>  File &quot;c:/Users/santi/Desktop/code/order/#test zone.py&quot;, line 8, in &lt;module&gt;
      ordering = [i, numberlist[next]]
  IndexError: list index out of range
  </code></pre>
  <p>What's happening here?</p>