pairs from a list

Peter Otten __peter__ at web.de
Wed Jan 23 13:32:01 EST 2008


Matthew_WARREN wrote:

> I'm just fiddling with this, am no great expert, but I added
> 
> def pairs5(x):
>         o=[]
>         for n in zip(x[::2],x[1:2]):

The second argument should be x[1::2].

>                 o.append(n)
>         return o
> 
> I dont know if that breaks any constraints placed on the problem, but I

It breaks the constraints unless the above is not cut-n-paste ;)
Also note that your pairs5() offers no advantage over

def pairs6(x):
    return zip(x[::2], x[1::2])

Peter



More information about the Python-list mailing list