Loop over list of pairs

Anton Vredegoor anton at vredegoor.doge.nl
Thu Jun 5 19:15:17 EDT 2003


Thomas Güttler <guettler at thomas-guettler.de> wrote:

>What is the prefered way of loop over
>a list like this?
> mylist=[1, "one", 2, "two", 3, "three"]

Python23 style:

    mylist=[1, "one", 2, "two", 3, "three"]
    for pair in zip(mylist[::2],mylist[1::2]):
        print pair

Anton




More information about the Python-list mailing list