I am writing a program to randomly generate groups for the office scavenger hunt I am organizing so I wrote this simple code quickly to simulate picking names out of a hat but only more fairer, but not exactly sure why it isn't working, it doesn't return all the names, for example I have entered 6 names into the list but it only returns 4 of them like this:
Group 1 consists of;
Chris
Ryan
Paul
Group 2 consists of;
Alex
I don't have much experience with removing elements from a list so it could well just be me doing it wrong. Any insight would be helpful.
import random
participants=["Alex","Elsie","Elise","Kimani","Ryan","Chris","Paul"]
group=1
membersInGroup=3
for participant in participants:
if membersInGroup==3:
print("Group {} consists of;".format(group))
membersInGroup=0
group+=1
person=random.choice(participants)
print(person)
membersInGroup+=1
participants.remove(str(person))