Using Python, I want to randomly select people from a list and put them in groups of 5 without selecting the same person more than once. The people are defined by 2 criteria: age and sex. The list of people looks like this:
PPL= [1, 4, 6], [2, 5, 5], [3, 7, 3], [4, 2, 8], [5, 4, 6]
where the 3 numbers in each list represent: age category (1-5), # of males, # of females.
I realize the groupings of 5 don't really matter, as all I have to do is make a random list (and then I could count off 5 at a time), but I'm not sure how to make a random list without reusing people. Any suggestions?
I have started with the following (which really just prints the remaining males and females):
import random
PPL = [1, 4, 6], [2, 5, 5], [3, 7, 3], [4, 2, 8], [5, 4, 6]
age = range(0, 6)
gender = [1, 2]#1 = male, #2 = female
randomAge = random.choice(age)
randomGender = random.choice(gender)
count = 0
PPLcounter = 0
for P in PPL:
while P[randomGender] > 0:
PPL[PPLcounter][randomGender] = P[randomGender] - 1
MRemaining = PPL [PPLcounter][1]
FRemaining = PPL [PPLcounter][2]
count = count+1
print count, MRemaining, FRemaining
PPLcounter += 1