Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://862342]
help
Chatterbox?
[choroba]: As discussed in Using the DATA file handle for ARGV, I usually start my "fun" scripts with *ARGV = *DATA{IO} unless @ARGV;
[choroba]: this was just a remainder
[Discipulus]: ah thanks i forgot that thread (even if i saved it in my homenode)..
[Discipulus]: the node i discovered yesterday nigth was also interesting

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2016-12-06 08:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (101 votes). Check out past polls.