splitting a list into n groups

Paul Rubin http
Wed Oct 8 15:56:32 EDT 2003


Rajarshi Guha <rajarshi at presidency.com> writes:
>   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)

groups = [a[i:i+(len(a)//5)] for i in range(5)]




More information about the Python-list mailing list