一般想法:
- Jean chose 1,2,3,4,5
- Claude chose 1,2,3,4,5
- Van chose 1,2,3,4,5
- Dam chose 1,2,3,4,5
我希望得到最后结果,给出这些结果:
更新1:
from collections import OrderedDict
ids_names = {
("01", "Jean"),
("02", "Claude"),
("03", "Van"),
("04", "Damme"),
("05", "Kristopher"),
("06", "Bianca"),
}
week_pool = ([1,2,3,4,5,6,7])
employee_choices = OrderedDict([
("01", [1,2,3,4,5]),
("02", [1,2,3,4,5]),
("03", [1,2,3,4,5]),
("04", [1,2,3,4,5]),
("05", [2,3,4,5,6]),
("06", [1,2,3]),
])
assignments = [ ]
tracking = {week_num: 0 for week_num in week_pool}
for element in employee_choices.items():
assignments.append(week_pool)
print('assignments: {}'.format(assignments))
for week_num in employee_choices:
if tracking[week_pool] < 3:
assignments[-1].append(week_pool)
tracking[week_num] += 1
if len(assignments[-1]) == 2:
break回溯(最近一次调用):第30行,在if trackingweek_pool < 3: TypeError: unhashable type:'list‘
更新工作!
weeks = list(range(1, 52))
tracking = {week_num: 0 for week_num in weeks}
assignments = [ ]
for preferences in [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]]:
assignments.append([ ])
print('assignments: {}'.format(assignments))
for week_num in preferences:
if tracking[week_num] < 3:
assignments[-1].append(week_num)
tracking[week_num] += 1
if len(assignments[-1]) == 2:
break发布于 2017-08-31 21:43:45
修订版
from collections import OrderedDict
# Translate employe ids
ids_names = {
("01", "Jean"),
("02", "Claude"),
("03", "Van"),
("04", "Damme"),
("05", "Kristopher"),
("06", "Bianca"),
}
week_pool = list(range(1, 53))
employee_choices = OrderedDict([
("01", [1,2,3,4,5]),
("02", [1,2,3,4,5]),
("03", [1,2,3,4,5]),
("04", [1,2,3,4,5]),
("05", [2,3,4,5,6]),
("06", [1,2,3]),
])描述
08-31:你的开局很好。我将在这里更新笔记,并给你提示。几个小音符:
range()是获取整数跨度的一种更短的方法,但您的方法也有效。OrderedDict是一个很好的选择。你可以用这个来安排资历。你只需要确保你的每周都在一个单独的容器里,例如一张清单。我为后面的点添加了一些额外的名字。目标
https://stackoverflow.com/questions/45969329
复制相似问题