If we have a list:
1 |
my_list = ['one', 'two', 'three', 'four'] |
in order to go through the elements of this list in pairs from the current to the next, we can use the following code:
1 2 |
for first, next in zip(my_list, my_list[1:]): print(first, next) |
Results:
1 2 3 |
one two two three three four |