生成一段python写的代码,用来实现众包当中存在的任务分配
时间: 2023-03-01 18:05:51 浏览: 134
下面是一段实现任务分配的简单 Python 代码:
```
tasks = ['task1', 'task2', 'task3', 'task4']
assigned = {}
def assign_task(worker):
for task in tasks:
if task not in assigned.values():
assigned[worker] = task
break
workers = ['worker1', 'worker2', 'worker3']
for worker in workers:
assign_task(worker)
print(assigned)
```
代码实现的功能是:给定一个任务列表 `tasks` 和一个工人列表 `workers`,每个工人只能分配一个任务,最后打印出每个工人分配的任务。
阅读全文