splitting a list into n groups

Terry Reedy tjreedy at udel.edu
Wed Oct 8 15:47:54 EDT 2003


"Rajarshi Guha" <rajarshi at presidency.com> wrote in message
news:pan.2003.10.08.17.42.18.956301.22624 at presidency.com...
> Hi,
>   is there an efficient (pythonic) way in which I could split a list
into
> say 5 groups? By split I mean the the first x members would be one
group,
> the next x members another group and so on 5 times. (Obviously x =
> lengthof list/5)
>
> I have done this by a simple for loop and using indexes into the
list.
> But it does'nt seemm very elegant

Does it work correctly for all input cases?  Is it readable?  Is it
acceptibly fast?  If so, it is probably 'Pythonic' enough.

TJR






More information about the Python-list mailing list