Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get 80% random elements from a list?

Tags:

python

I have a list with integers. I want to choose 80% from them. For example, for [1,...,30] I want to keep 80% from the list with random so I get for example [1,...,32]\[3,7,19,21,25,29] (It means it deleted 3,7,19,21,25,29 values from the original list. How can I do it?

like image 573
vesii Avatar asked Oct 30 '25 16:10

vesii


1 Answers

import random

random.sample(lst, k=round(len(lst) * 0.8))
like image 67
Pierre D Avatar answered Nov 01 '25 06:11

Pierre D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!