Skip to content
Advertisement

python multiply list elements inside list

I use lists to randomly pick an element over many iterations (to create artificial data sets). To change the probability of getting a certain element, I’m repeatedly adding those elements that should have a higher change of being picked, so instead of

JavaScript

I would do

JavaScript

Is there a better way to do this inline? I tried

JavaScript

but this results in

JavaScript

Advertisement

Answer

You can do it in one line actually.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement