Suppose I set the list l = range(100)
. I know that random.sample(l, 20)
will spit a random list similar to [80, 90, 66, 37, 7, 34, 9, 33, 69, 35, 87, 39, 47, 68, 41, 51, 10, 52, 42, 11]
. I would need to sample from the same list, but in the different way. This time, the sample()
function has to output a list where each element is a list of consecutive numbers. For instance, the output of sample(range(100), 3, 4)
might be [[4, 5, 6, 7], [12, 13, 14, 15], [60, 61, 62, 63]]
. How can I do that
UPDATE
If the list is list_inst=[12, 8, 0, 12, 19, 20, 13, 19, 78, 21, 13, 85]
, than sample(list_inst, 3, 4)
might output [[12, 8, 0, 12], [0, 12, 19, 20], [13, 19, 78, 21]]
.
Aucun commentaire:
Enregistrer un commentaire