You can simply use slicing:

for item in I[1:]:
    print(item)

And if you want indexing, use pythonic-style enumerate:

START = 1
for index, item in enumerate(I[START:], START):
    print(item, index)
Answer from Mastermind on Stack Overflow
Discussions

python - Iterating over every two elements in a list - Stack Overflow
I do have some questions since I am sort of new to some of python's libraries. Zip is one of them. first on a[::2] - if I understand correctly this will add 2 spaces for every iteration starting with the first value in the list. 1,3,5,etc. Now, on a[1::2] - 2021-07-02T19:54:45.017Z+00:00 ... Now, on a[1::2] - this will add +1 from ... More on stackoverflow.com
🌐 stackoverflow.com
Start iteration from second element in Python - Stack Overflow
I have the next part of code in python: for (script, location) in self.device.scripts: How can I start to take elements from the second pair of the given list? And if that is possible where shoul... More on stackoverflow.com
🌐 stackoverflow.com
March 24, 2018
python - Iterate every 2 elements from list at a time - Stack Overflow
This doesn't work, it prints [(1, ... (9, 0)]. Elements are being repeated. You need to add a step to your range. 2024-03-23T20:21:09.98Z+00:00 ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Does the Agonizing Blast Eldritch Invocation still add the Charisma modifier to the damage of each beam from Eldritch Blast? ... Animating a transition from one color to a second color ( rainbow ... More on stackoverflow.com
🌐 stackoverflow.com
February 13, 2014
pandas - iterate on python list (a list from second item from another list) - Stack Overflow
Unless I'm missing something you're overcomplicating. Just iterate through the main list and print the 2nd element of the list you get on each loop, e.g.: ... Python is has some really nice ways of iterating through lists so you don't need to use the range method. More on stackoverflow.com
🌐 stackoverflow.com
June 3, 2019
🌐
Reddit
reddit.com › r/learnpython › looping until the second to last element in a list, what's best practice?
r/learnpython on Reddit: Looping until the second to last element in a list, what's best practice?
January 11, 2024 -

edit: forgot to mention I want the indeces not just the items

the methods I can think of are:

for i in range(len(arr) - 1)

for i, e in enumerate(arr[:len(arr) - 1])

I know range(len(arr)) is frowned upon, but I don't see how it's worse than enumerate in this case. In fact using enumerate on a shortened list and calling len to find the second to last element of that list seems extremely clunky and far less readable.

What's the best practice for doing this?

Top answer
1 of 16
350

Starting with Python 3.12, you can use the batched() function provided by the itertools module:

from itertools import batched

for x, y in batched(l, n=2):
    print("%d + %d = %d" % (x, y, x + y))

Otherwise, you need a pairwise() (or grouped()) implementation.

def pairwise(iterable):
    "s -> (s0, s1), (s2, s3), (s4, s5), ..."
    a = iter(iterable)
    return zip(a, a)

for x, y in pairwise(l):
   print("%d + %d = %d" % (x, y, x + y))

Or, more generally:

def grouped(iterable, n):
    "s -> (s0,s1,s2,...sn-1), (sn,sn+1,sn+2,...s2n-1), (s2n,s2n+1,s2n+2,...s3n-1), ..."
    return zip(*[iter(iterable)]*n)

for x, y in grouped(l, 2):
   print("%d + %d = %d" % (x, y, x + y))

In Python 2, you should import izip as a replacement for Python 3's built-in zip() function.

All credit to martineau for his answer to my question, I have found this to be very efficient as it only iterates once over the list and does not create any unnecessary lists in the process.

N.B: This should not be confused with the pairwise recipe in Python's own itertools documentation, which yields s -> (s0, s1), (s1, s2), (s2, s3), ..., as pointed out by @lazyr in the comments.

Little addition for those who would like to do type checking with mypy on Python 3:

from typing import Iterable, Tuple, TypeVar

T = TypeVar("T")

def grouped(iterable: Iterable[T], n=2) -> Iterable[Tuple[T, ...]]:
    """s -> (s0,s1,s2,...sn-1), (sn,sn+1,sn+2,...s2n-1), ..."""
    return zip(*[iter(iterable)] * n)
2 of 16
282

Well you need tuple of 2 elements, so

data = [1,2,3,4,5,6]
for i,k in zip(data[0::2], data[1::2]):
    print str(i), '+', str(k), '=', str(i+k)

Where:

  • data[0::2] means create subset collection of elements that (index % 2 == 0)
  • zip(x,y) creates a tuple collection from x and y collections same index elements.
🌐
CodeFatherTech
codefather.tech › home › blog › how do you get every other element from a python list?
How Do You Get Every Other Element From a Python List?
December 8, 2024 - This time we have started by index 1, remember that the index for lists starts from zero. You can use a for loop and the range() function to print every second element of a list
🌐
YouTube
youtube.com › codemade
python loop through list from second element - YouTube
Download this code from https://codegive.com Certainly! Below is an informative tutorial on how to loop through a Python list starting from the second elemen...
Published: January 21, 2024
Views: 130
Find elsewhere
🌐
LearnPython.com
learnpython.com › blog › python-list-loop
7 Ways to Loop Through a List in Python | LearnPython.com
Another method for looping through a Python list is the range() function along with a for loop. range() generates a sequence of integers from the provided starting and stopping indexes.
🌐
Dot Net Perls
dotnetperls.com › every-nth-element-python
Python - List Every Nth Element - Dot Net Perls
This logic filters on the index, and returns the required elements. Python code that uses lambda expressions and methods like filter() or map() can be effective. But often it is clearer to just use a for-loop. Consider a list with 4 values: the one-character strings from "abcd." By taking every second element (argument 2) we should get "a" and "c."
🌐
Real Python
realpython.com › python-enumerate
Python enumerate(): Simplify Loops That Need Counters – Real Python
October 21, 2025 - In this example, you create a Python list called values with two elements, "first" and "second". Then, you pass values to enumerate() and assign the return value to enumerate_instance. When you print enumerate_instance, you’ll see that it’s an enumerate object with a particular memory address. Then, you use Python’s built-in next() to get the next value from enumerate_instance.
🌐
W3Schools
w3schools.com › python › python_lists_loop.asp
Python - Loop Lists
You can loop through the list items by using a for loop.
🌐
Python Pool
pythonpool.com › home › tutorials › how to iterate through a list in python
11 Powerful Methods to Iterate Through List in Python
July 14, 2026 - Learn how to iterate through a Python list with for loops, enumerate(), range(), while loops, and list comprehensions.
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 402440 › looping-through-a-list-starting-at-index-2
python - Looping through a list starting at index ... [SOLVED] | DaniWeb
December 22, 2011 - If you only need words from index 2 onward, avoid indexing in a loop and either slice the word list or use an iterator slice.
🌐
Java2Blog
java2blog.com › home › python › python list › get every other element in list in python
Get Every Other Element in List in Python - Java2Blog
October 4, 2022 - Here is article on how to increment for loop by 2 in Python. List comprehension is capable of creating a list with reference to an already existing list. It also reduces the chunk of code and makes the code more compact. Here, we utilize the range() function with conditionals rather than the convention start, stop, and step parameters. The following code uses list comprehension and the range() function with conditionals to get every other element in a list in Python.
🌐
Quora
quora.com › How-do-you-iterate-over-two-lists-in-Python
How to iterate over two lists in Python - Quora
Answer: I usually do this with 2 approaches 1st Using “for” loop [code]list1 = [1, 2, 3] list2 = ['a', 'b', 'c'] for i in range(len(list1)): print(list1[i], list2[i]) [/code]2nd Using zip() function [code]list1 = [1, 2, 3] list2 = ['a', 'b', 'c'] for x, y in zip(list1, list2): print(x, ...