栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python 自用选择器

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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()
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/971556.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号