Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python Choice, get / return selected Wieght value

I use .Choices to select a value randomly whith weight value.

Is it possible to store the used weight value to a variable?

var = random.choices(population=A, B, C, weights=[20, 20, 60])

Thanks!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just store it before you give it to the function. You must also change the way you assign the population. Your Code sould look more like this:

my_weights = [20, 20, 60]
my_population = ["A", "B", "C"]
var = random.choices(population = my_population, weights = my_weights)

Like this the code should ork an you could access the weights and population afterwards in my_weights and my_population.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading