I need to create 3 lists from my list1. One with 70% of the values and two with 20% and 10%.
list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# listOutput70 = select 70% of list1 items(randomly)
# with the remaining create two lists of 20% and 10%
#the output can be something like:
#listOutput70 = [2,7,9,8,4,10,3]
#listOutput20 = [1,5]
#listOutput10 = [6]
I already have some code to generate a percentage output, but works only for one list.
import random
def selector():
RandomSelection = []
mySel = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
PercentEnter= 70
New_sel_nb = len(mySel)*int(PercentEnter)/100
while len(RandomSelection) < New_sel_nb:
randomNumber = random.randrange(0, len(mySel),1)
RandomSelection.append(mySel[randomNumber])
RandomSelection = list(set(RandomSelection))
print(RandomSelection)
selector()
#[2, 3, 6, 7, 8, 9, 10]
PercentEnter= PercentEnter?