[Tutor] Process list elements as consecutive pairs
Peter Otten
__peter__ at web.de
Sun Mar 7 08:48:37 CET 2010
RĂ¼diger Wolf wrote:
> I am trying to Process list elements as consecutive pairs into
> consecutive pairs.
> Any pythonic suggestions?
>
> listin = [1,2,3,4,5,6,7,8,9,10]
> I want to process as consecutive pairs
> 1,2
> 3,4
> 5,6
> 7,8
> 9,10
>>> listin = [1,2,3,4,5,6,7,8,9,10]
>>> it = iter(listin)
>>> zip(it, it)
[(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)]
If listin as an odd length the last item will be lost.
Peter
More information about the Tutor
mailing list