How do I loop through a list by twos? [duplicate]

I want to loop through a Python list and process 2 list items at a time. Something like this in another language:

for(int i = 0; i < list.length(); i+=2)
{
   // do something with list[i] and list[i + 1]
}

What’s the best way to accomplish this?

7 Answers
7

Leave a Comment