Hi!
I have a list [1,2,3,4,5,6] which I'd like to iterate as (1,2), (3,4),
(5,6). I can of course roll my own, but I was wondering if there was
already some existing library function that already does this.
def as_pairs(seq):
i = iter(seq)
yield (i.next(), i.next())
Question to this
On Tue, May 11, 2010 at 12:09 AM, Ulrich Eckhardt
eckha...@satorlaser.com wrote:
Hi!
I have a list [1,2,3,4,5,6] which I'd like to iterate as (1,2), (3,4),
(5,6). I can of course roll my own, but I was wondering if there was
already some existing library function that already does this.
When
Ulrich Eckhardt a écrit :
Hi!
I have a list [1,2,3,4,5,6] which I'd like to iterate as (1,2), (3,4),
(5,6). I can of course roll my own, but I was wondering if there was
already some existing library function that already does this.
l = range(10)
for x, y in zip(l[::2], l[1::2]):
...
Ulrich Eckhardt wrote:
I have a list [1,2,3,4,5,6] which I'd like to iterate as (1,2), (3,4),
(5,6). I can of course roll my own, but I was wondering if there was
already some existing library function that already does this.
def as_pairs(seq):
i = iter(seq)
yield (i.next(),