Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Rosetta code: Split an array into chunks

by MonkOfAnotherSect (Sexton)
on Sep 28, 2010 at 02:45 UTC ( #862342=note: print w/ replies, xml ) Need Help??


in reply to Rosetta code: Split an array into chunks

The simplest Python version is probably:

def chunk_array(n, vals): return "\n".join(" ".join(vals[i:i+n]) for i in range(0, len(vals), n))
Given that you have to return one big string anyway, it's not worthwhile doing anything more fancy with generators/iterators.


Comment on Re: Rosetta code: Split an array into chunks
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://862342]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2015-07-31 06:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls