Created
September 18, 2015 07:38
-
-
Save c-garcia/b4311c7c3b1804aeaecd to your computer and use it in GitHub Desktop.
Python equivalent to clojure partition (simple case)
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
def partition(seq, num): | |
"Partititons a seq en disjoint seqs of up to num elems" | |
return [seq[start:start+count] \ | |
for (start, count) in \ | |
[(num * x,y) for (x,y) in \ | |
zip(range(len(seq)/num), [num]*(num*(len(seq)/num)))] + | |
[(num * (len(seq)/num), len(seq) % num)] | |
if count >0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Having seen the generator https://news.ycombinator.com/item?id=668544 , mine is just an intellectual exercise :)