| In other words, (pair list) but the pair size doesn't need to be 2 Looking at pair's implementation doesn't help much, (def pair (xs (o f list))
(if (no xs)
nil
(no (cdr xs))
(list (list (car xs)))
(cons (f (car xs) (cadr xs))
(pair (cddr xs) f))))
Seems rather cryptic and hard to play with :/This is how I'd do it in python: def split_to_groups(list, size):
groups = []
for s in range(0, len(list), size):
groups.append(list[s:s+size])
return groups
Test: >>> split_to_groups(range(20), 3)
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14], [15, 16, 17], [18, 19]]
|