Beispiel #1
0
#             count+=1
#     return count
#
# # 查找所有部门编号是9001的员工数量
# def find02():
#     count=0
#     for item in list_employees:
#         if item.did==9001:
#             count+=1
#     return count

# def condition01(item):
#     return item.money>20000
#
# def condition02(item):
#     return item.did==9001
#
# def get_count(func):
#     count = 0
#     for item in list_employees:
#         if func(item):
#             count += 1
#     return count

count1 = IterableHelper.get_count(list_employees,
                                  lambda item: item.money > 20000)
print(count1)

count2 = IterableHelper.get_count(list_employees,
                                  lambda item: item.did == 9001)
print(count2)
Beispiel #2
0
    Employee(1002, 9001, "孙悟空", 50000),
    Employee(1003, 9002, "猪八戒", 20000),
    Employee(1004, 9001, "沙僧", 30000),
    Employee(1005, 9001, "小白龙", 15000),
]
# def find01():
#     for item in list_employees:
#         if item.eid==1003:
#             return item
#
# def find02():
#     for item in list_employees:
#         if item.name=="孙悟空":
#             return item


def condtion01(item):
    return item.eid == 1003


def condtion02(item):
    return item.name == "孙悟空"


# def find_single(func):
#     for item in list_employees:
#         if func(item):
#             return item
emp = IterableHelper.find_single(list_employees, condtion01)
print(emp.__dict__)
Beispiel #3
0

list_employees = [
    Employee(1001, 9002, "师父", 60000),
    Employee(1002, 9001, "孙悟空", 50000),
    Employee(1003, 9002, "猪八戒", 20000),
    Employee(1004, 9001, "沙僧", 30000),
    Employee(1005, 9001, "小白龙", 15000),
]
# def find01():
#     for item in list_employees:
#         yield item.name
#
#
# def find02():
#     for item in list_employees:
#         yield item.eid,item.money

# def condtion01(number):
#     return number.name
#
#
# def condtion02(number):
#     return number.eid,number.money

for name in IterableHelper.select(list_employees, lambda number: number.name):
    print(name)

for item in IterableHelper.select(list_employees, lambda number:
                                  (number.eid, number.money)):
    print(item)
Beispiel #4
0
#         if min_eid.eid>list_employees[item].eid:
#             min_eid=list_employees[item]
#     return min_eid
# # 在员工列表中查找薪资最少的员工
# def find02():
#     min_money=list_employees[0]
#     for item in range(1,len(list_employees)):
#         if min_money.money>list_employees[item].money:
#             min_money=list_employees[item]
#     return min_money

# def condition01(min_eid):
#     return min_eid.eid
#
# def condition02(min_money):
#     return min_money.money

# def get_min(func):
#     min_value = list_employees[0]
#     for item in range(1,len(list_employees)):
#         if func(min_value)>list_employees[item].money:
#             min_value=list_employees[item]
#     return min_value

min01 = IterableHelper.get_min(list_employees, lambda min_eid: min_eid.eid)
print(min01.__dict__)

min02 = IterableHelper.get_min(list_employees,
                               lambda min_money: min_money.money)
print(min02.__dict__)
    EmployeeModel(1001, 9003, "林玉玲", 13000),
    EmployeeModel(1002, 9005, "王荆轲", 16000),
    EmployeeModel(1003, 9003, "刘岳浩", 11000),
    EmployeeModel(1004, 9004, "冯舜禹", 17000),
    EmployeeModel(1005, 9005, "曹海欧", 15000),
    EmployeeModel(1006, 9005, "魏鑫珑", 12000),
]

# IterableHelper.del_all(list_employee, lambda emp: emp.money < 15000)

# for employee in list_employee:
#     print(employee.__dict__)
# count = IterableHelper.del_all(list_employee, lambda emp: emp.did == 9005)

# for employee in list_employee:
#     print(employee.__dict__)



# max_employe = IterableHelper.get_max(list_employee, lambda emp: emp.money)
# print(max_employe.__dict__)
# print(IterableHelper.get_max(list_employee, lambda emp: emp.eid).__dict__)

# IterableHelper.ascending_order(list_employee, lambda emp: emp.money)
IterableHelper.ascending_order(list_employee, lambda emp: emp.eid)
for employee in list_employee:
    print(employee.__dict__)

sorted(list_employee,key= lambda emp:True)

Beispiel #6
0
# print(list_employees)

# # 员工编号对员工列表进行升序排列
# def get_des02():
#     for r in range(len(list_employees)-1):
#         for c in range(r+1,len(list_employees)):
#             if list_employees[r].eid >list_employees[c].eid:
#                 list_employees[r],list_employees[c]=list_employees[c],list_employees[r]
#     yield list_employees

# def condition01(item):
#     return item.money
#
# def condition02(item):
#     return item.eid

# def order_by(func):
#     for r in range(len(list_employees)-1):
#         for c in range(r+1,len(list_employees)):
#             if func(list_employees[r]) >func(list_employees[c]):
#                 list_employees[r],list_employees[c]=list_employees[c],list_employees[r]

IterableHelper.order_by(list_employees,lambda item:item.money)
print(list_employees)
for item in list_employees:
    print(item)

IterableHelper.order_by(list_employees,lambda item:item.eid)
print(list_employees)
for item in list_employees:
    print(item)
        self.name = name
        self.atk_rate = atk_rate
        self.cost_sp = cost_sp
        self.duration = duration


list_skills = [
    Skill("横扫千军", 1, 50, 5),
    Skill("九阳神功", 3, 150, 6),
    Skill("降龙十八掌", 3, 150, 5),
    Skill("一阳指", 1.2, 0, 2),
    Skill("乾坤大挪移", 3.2, 30, 2),
    Skill("打狗棍", 1.3, 0, 6),
]

result = IterableHelper.find_single(list_skills, lambda emp: emp.name == "一阳指")
print(result.__dict__)

for list_skill in IterableHelper.find_all(list_skills,
                                          lambda emp: emp.atk_rate > 1):
    print(list_skill.__dict__)

for list_skill in IterableHelper.select(list_skills, lambda emp:
                                        (emp.name, emp.atk_rate)):
    print(list_skill)


class IterableHelper:
    @staticmethod
    def find_single(iterable, func):
        for item in iterable: