[pyar] Iterar sobre pares

Federico Heinz fheinz en vialibre.org.ar
Mar Jul 20 11:04:15 ART 2010


On 20/07/2010, Juanjo Conti wrote:
> Para:
> seq = range(8)
> for x in algo(seq)
> que cada vuelta de la iteracion sobre seq tome los respectivos
> valores: (0,1), (2,3), (3,4)...

List comprehension?

>>> for x in [(seq[2*i], seq[2*i+1]) for i in range(len(seq)/2)]:
...     print x
... 
(0, 1)
(2, 3)
(4, 5)
(6, 7)

	Fede



More information about the pyar mailing list