If I understand the objective correctly then my approach would be:
- shuffle the list
- slice list to evenly distributed chunks
- assign chunks to dates
Something like that:
- shuffle the list
- slice list to evenly distributed chunks
- assign chunks to dates
Something like that:
>>> import random >>> students = ['Joey', 'Henry', 'Daniel', 'James', 'Samantha', 'Jose', 'Salvator', 'Paul', 'Steve', 'Mary', 'Kyle', 'Marcus', 'Pat'] >>> dates = ['Jan 6', 'Jan 8', 'Jan 10'] >>> step = len(students) // len(dates) >>> random.shuffle(students) # shuffles list in place >>> students ['Paul', 'Salvator', 'Daniel', 'Mary', 'Pat', 'Jose', 'Marcus', 'Steve', 'James', 'Samantha', 'Joey', 'Henry', 'Kyle'] >>> assignments = dict() >>> for i, date in enumerate(dates): ... assignments[date] = students[i*step:i*step+step] ... >>> assignments {'Jan 6': ['Paul', 'Salvator', 'Daniel', 'Mary'], 'Jan 8': ['Pat', 'Jose', 'Marcus', 'Steve'], 'Jan 10': ['James', 'Samantha', 'Joey', 'Henry']}It assumes that step is integer i.e. there are even numbers of students for each day (currently 'Kyle' is left out). Should he be added to first or last or randomly? Are there constraints how many students can present in one day?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.