samedi 13 mars 2021

Creating random, non recurrent groups of undetermined size from a list

I want to create a program where a user can input what the maximum size of the groups is that they want. These groups are formed from a list of names from a submission form. The idea is that there are multiple rounds in which the names are paired in the requested maximum group size and each round does not create previously formed groups. Also, no one should be left out, so no groups of 1 person.

I have two problems: first off: if I have a list of 10 names and I input that I want max size groups of 3 persons, I get 3 groups of 3 persons and 1 of 1, but it should be 3, 3, 2, 2. I used two different functions I found on here, but both have the same problem.

Secondly, I have no idea how to make sure that in a new round there won't be any groups from previous round.

I am pretty new to programming, so any tips are welcome. This is the first function I have:

members = group_size()

def teams(amount, size):
    for i in range(0, len(amount), size):
        yield amount[i:i + size]

participants = Row_list_names
random.shuffle(participants)

print("These are your groups:")
print(list(teams(participants, members)))

And this is the second:

members = group_size()
participants = Row_list_names
random.shuffle(participants)
for i in range(len(participants) // members + 1):
    print('Group {} consists of:'.format(i+1)) 
    group = participants[i*members:i*members + members]
    for participant in group:
        print(participant)

group_size() returns an integer number for how many people should be in the group.




Aucun commentaire:

Enregistrer un commentaire