Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a list
a = [1,2,3,4,5,6,7,89,34,654,354,84,6845,351,68,5,645,645,5312,65]

I want to randomly sample 8 elements from this list, so I use the following code

`import random
random.seed(1)
b = random.sample(a,8)`

Now I want to randomly sample 5 elements from the list again, but these 5 elements should not include any of the 8 elements sampled earlier.
How can I achieve that?

Thanks for the help!

What I have tried:

I have already mentioned it in the question
Posted
Updated 31-Mar-18 23:55pm

1 solution

The simplest way is: as you sample the elements, remove them from the collection.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900