Say I have a list of 200 unique random integers called masterlist.
I want to generate a list of 10 lists called container so that: l1 has 2 random numbers coming from masterlist, repetitions excluded; l2 has 4 elements, l3 has 6 elements, and so forth.
I know I can create my container list like this:
comb=[[] for i in range(10)]
and that I can select a random value from a list using random.choice().
What is the best Pythonic way to nest the populating process of these 10 lists, so that I create one list, append the correct number of values checking that there are no repetitions, and proceed on to the next?
Aucun commentaire:
Enregistrer un commentaire