vendredi 8 avril 2016

Python: dividing a list into chunks with varying size

I am stuck on a problem involving splitting up a List into different sized chunks. I want to have a list that is randomly split in either pairs of 2 or 3.

example:

L = [1,1,1,1,1,1,1,1,1,1,1,1]

and I want to get something out like:

L2 = [(1,1,1),(1,1),(1,1),(1,1,1),(1,1)]

but this I want to be random, so that the distribution of pairs and tripplets changes everytime the code is ran.

Can someone help?




Aucun commentaire:

Enregistrer un commentaire