Skip to content

Instantly share code, notes, and snippets.

@narma
Last active October 2, 2015 21:47
Show Gist options
  • Save narma/2328169 to your computer and use it in GitHub Desktop.
Save narma/2328169 to your computer and use it in GitHub Desktop.
create table from plain data list with rows, columns in each chunk
(defn tablize [coll rows cols]
(map (fn [p]
(map #(take cols (take-nth rows (drop % p))) (range rows)))
(partition-all (* rows cols) coll)))
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)
))
""" 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