Created
September 2, 2018 10:50
-
-
Save arbel03/bae8b43a572a50a2110643cbd7aeb43e to your computer and use it in GitHub Desktop.
Create random groups from a list easily
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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