Last active
October 2, 2015 21:47
-
-
Save narma/2328169 to your computer and use it in GitHub Desktop.
create table from plain data list with rows, columns in each chunk
This file contains hidden or 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
(defn tablize [coll rows cols] | |
(map (fn [p] | |
(map #(take cols (take-nth rows (drop % p))) (range rows))) | |
(partition-all (* rows cols) coll))) |
This file contains hidden or 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
from itertools import izip | |
def tablize(coll, rows, cols): | |
s = rows*cols | |
l = len(coll) | |
return izip(*( | |
map(lambda p: p[r::rows], | |
(coll[i*s:(i+1)*s] for i in range((l+s-l%s)/s))) | |
for r in range(rows) | |
)) |
This file contains hidden or 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
""" from range(1, 18) with 3 rows and 4 columns it's create like this: | |
4 columns | |
############# | |
1 4 7 10 # | |
2 5 8 11 # 3 rows | |
3 6 9 12 # | |
13 16 | |
14 17 | |
15 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment