iterating "by twos"

giltay at gmail.com giltay at gmail.com
Tue Jul 29 20:36:20 CEST 2008


On Jul 29, 1:36 pm, kj <so... at 987jk.com.invalid> wrote:
> Is there a special pythonic idiom for iterating over a list (or
> tuple) two elements at a time?

     I use this one a lot:

for x, y in zip(a, a[1:]):
    frob(x, y)

Geoff G-T




More information about the Python-list mailing list