in reply to Rosetta code: Split an array into chunks
The simplest Python version is probably:
Given that you have to return one big string anyway, it's not worthwhile doing anything more fancy with generators/iterators.def chunk_array(n, vals): return "\n".join(" ".join(vals[i:i+n]) for i in range(0, len(vals), n))
|
---|
In Section
Meditations