概述
from asyncio.windows_events import NULL
import random
import copy
MOSTNUM = 2
"""
1 打乱people列表
2 从列表中取出元素, 取的次数 len(time) 次
3 一次取 (1 ~ 2) 个元素
4 将剩余元素加入 tmp 列表
5 从 tmp 列表取 (1 ~ 2) 个元素
6 所有元素取完, 重复操作
"""
class Selector:
def __init__(self, people, time, week) -> None:
self.people = people
self.time
= time
self.week
= week
def OnceSelect(self, people_list):
"""
当次选择
"""
select_dict = {}
for times in time:
number_of_people = random.randint(1, MOSTNUM)
select_list = []
for i in range(number_of_people):
if len(people_list) == 0:
people_list = copy.copy(self.people)
random.shuffle(people_list)
selected = people_list.pop(0)
select_list.append(selected)
select_dict.update(
{
times : select_list
}
)
return select_dict, people_list
def WeekSelect(self):
operation_list = copy.copy(self.people)
for i in self.week:
select_dict, operation_surplus = self.OnceSelect(operation_list)
if len(operation_surplus):
operation_list = operation_surplus
print(select_dict)
if __name__ == "__main__":
# 待选择人员
people = ["A", "B", "C", "D", "E", "F", "G"]
# 日期
time = ["1", "2", "3", "4"]
# 周次
week = ["一", "二", "三", "四"]
obj = Selector(people, time, week)
obj.WeekSelect()
最后
以上就是会撒娇热狗为你收集整理的python 自用选择器的全部内容,希望文章能够帮你解决python 自用选择器所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复