Is it possible to randomly assign data points from one list to a new list by proportion?
For example: let's say that I have a list
data = [[20, 30, 40, 50 ,60, 70, 80, 90] and I want to assign 50% of the elements into a new list by random:
import random
newlst = random.sample(data, k = 4)
newlst = [30, 80, 70, 50]
I know that k is the number of exact elements assigned to the new list (newlst has 4 elements from data), is there a way that I can assign elements from data into a new list by proportion (e.g. assign 50% of the data into a new list would give me a new list with 4 elements)?
Many Thanks!
Aucun commentaire:
Enregistrer un commentaire