mardi 22 novembre 2022

Python - Random.sample from a range with excluded values (array)

I am currently using the random.sample function to extract individuals from a population.

ex:

n = range(1,1501)

result = random.sample(n, 500) print(result)

in this example I draw 500 persons among 1500. So far, so good..

Now, I want to go further and launch a search with a list of exclude people.

exclude = [122,506,1100,56,76,1301]

So I want to get a list of people (1494 persons) while excluding this array (exclude)

I must confess that I am stuck on this question. Do you have an idea ? thank you in advance!

I am learning Python language. I do a lot of exercise to train. Nevertheless I block ue on this one.




Aucun commentaire:

Enregistrer un commentaire