Skip to content

Instantly share code, notes, and snippets.

@azbones
Created March 4, 2018 19:46
Show Gist options
  • Save azbones/95f256070d306003cc04cc87c90e6e48 to your computer and use it in GitHub Desktop.
Save azbones/95f256070d306003cc04cc87c90e6e48 to your computer and use it in GitHub Desktop.
randomly assign list of students to a set number of groups
# randomly assign list of students to a set number of groups
import random
def partition(lst, n):
division = len(lst) / float(n)
groups = [lst[int(round(division * i)): int(round(division * (i + 1)))] for i in range(n) ]
return groups
students = []
random.shuffle(students)
groups = partition(students,4)
print(groups)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment