Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iterating over two values of a list at a time in python [duplicate]

Tags:

python

list

I have a set like (669256.02, 6117662.09, 669258.61, 6117664.39, 669258.05, 6117665.08) which I need to iterate over, like

    for x,y in (669256.02, 6117662.09, 669258.61, 6117664.39, 669258.05, 6117665.08)         print (x,y) 

which would print

    669256.02 6117662.09     669258.61 6117664.39     669258.05 6117665.08 

im on Python 3.3 btw

like image 492
Rasmus Damgaard Nielsen Avatar asked May 28 '13 10:05

Rasmus Damgaard Nielsen


People also ask

How do you loop through a pair in Python?

To iterate over all pairs of consecutive items in a list with Python, we can use zip with a for loop.


1 Answers

You can use an iterator:

>>> lis = (669256.02, 6117662.09, 669258.61, 6117664.39, 669258.05, 6117665.08) >>> it = iter(lis) >>> for x in it: ...     print (x, next(it)) ...      669256.02 6117662.09 669258.61 6117664.39 669258.05 6117665.08 
like image 81
Ashwini Chaudhary Avatar answered Sep 22 '22 05:09

Ashwini Chaudhary