[Tutor] Process list elements as consecutive pairs

greg whittier greg at thewhittiers.com
Fri Mar 5 19:03:45 CET 2010


On Fri, Mar 5, 2010 at 12:56 PM, Rüdiger Wolf <
rudiger.wolf at throughputfocus.com> 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
>

Not sure it's pythonic but

zip(listin[0::2],listin[1::2])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100305/7c31879f/attachment.html>


More information about the Tutor mailing list