Last active
December 20, 2015 12:39
-
-
Save hirokiky/6132839 to your computer and use it in GitHub Desktop.
[0, 1, 2, 3, 4, 5] => [[0, 1], [2, 3], [4, 5]]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chunker1 = lambda xs: zip(xs[:-1:2], xs[1::2]) | |
chunker2 = lambda xs: [xs[i:i+2] for i in range(0,len(xs),2)] | |
def chunker3(xs): | |
i = 0 | |
while xs[i:i+2]: | |
yield xs[i:i+2] | |
i += 2 | |
def chunker4(xs): | |
t = xs[::-1] | |
while t: | |
a = t.pop() | |
b = t.pop() | |
yield a, b | |
chunker5 = lambda xs: (lambda xs, size: zip(*tuple(xs[i::size] for i in range(size))))(xs, 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
これ素晴らしい https://gist.github.com/knzm/6133057