I'm trying to make a random group generator splitting a list of students into n nearly-equal partitions (for example, if there are 11 students and three groups, we would want two groups of four and one group of 3) . We need to repeat this process for x number of assignments. We read the list of students in from a file and read the groups out from a file. Here's the code I have so far:
import csv
import unittest
def studentgenerator(num_asmt, num_stud, student_list, 
assignment_teams):
    with open(student_list , "r") as student:
        list_students = csv.reader(student)
    student_groups = []
    for x in range (0, num_asmt):
        random.shuffle(list_students)
        div = len(list_students)/float(num_stud)
        for x in xrange(num_stud):
            student_groups = lst[int(round(div * x)): int(round(div * 
            (x + 1))]\
   for group in student_groups:
        with open(assignment_teams, "w") as team:
            list_assignment_groups = csv.writer(team)
            list_assignment_groups.writerow(group)
student_list.close()
assignment-teams.close()
I can't seem to get the partitioner to work the way I want it to, and I think that something's going wrong with reading in/out from files, but I'm not sure exactly what I'm doing wrong.
 
     
     
    