python 自用选择器

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()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值