Skip to content

Instantly share code, notes, and snippets.

@arbel03
Created September 2, 2018 10:50
Show Gist options
  • Save arbel03/bae8b43a572a50a2110643cbd7aeb43e to your computer and use it in GitHub Desktop.
Save arbel03/bae8b43a572a50a2110643cbd7aeb43e to your computer and use it in GitHub Desktop.
Create random groups from a list easily
import random
names = ["arbel", "liav", "yuval", "nevo", "matan", "nitzan", "gilad", "or"]
group_count = 2
groups = { group: [] for group in range(group_count) }
group_index = 0
while (len(names) != 0):
random.shuffle(names)
group_index = group_index%group_count
groups[group_index].append(names.pop())
group_index += 1
print '\n'.join(['group %d: %s'%(index, group) for index, group in groups.items()])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment