Exemplo n.º 1
0
# 技能列表 -- 转换为编号列表
# 技能列表 -- 转换为名称列表
from common.custom_list_tools import ListHelper

class Skill:
    def __init__(self, id, name, cd, atk, magic):
        self.id = id
        self.name = name
        self.cd = cd
        self.atk = atk
        self.magic = magic


list_skills = [
    Skill(101, "降龙十八掌", 2, 130, 15),
    Skill(102, "六脉神剑", 0, 100, 35),
    Skill(103, "一阳指", 2, 190, 0),
    Skill(104, "葵花点穴手", 0, 120, 15),
    Skill(105, "韦陀掌", 5, 90,0),
]

from common.custom_list_tools import ListHelper

list01 = list(ListHelper.select(list_skills, lambda item: item.id))
print(list01)

list02 = list(ListHelper.select(list_skills, lambda item: item.name))
print(list02)

list03 = list(ListHelper.select(list_skills, lambda item: (item.id, item.name)))
print(list03)
Exemplo n.º 2
0
# list01 = [101,102,103,104,105]

# 17:15
# def find_demo01(target):
#     for item in target:
#         yield item.id
#         yield xxx(item)
#
# def find_demo02(target):
#     for item in target:
#         yield item.name

# def xxx(item):
#     return item.id

for item in ListHelper.select(list_skills, lambda item: item.name):
    print(item)

# 练习:17:29
# 解决的问题:求和 sum
#  技能列表 -->  所有技能编号的和
#  技能列表 -->  所有技能cd的和

# list_skills = [
#     SkillData(101, "降龙十八掌", 60, 10, 5),
#     SkillData(102, "如来神掌", 50, 15, 0),
#     SkillData(103, "六脉神剑", 0, 20, 8),
#     SkillData(104, "一阳指", 0, 50, 15),
#     SkillData(105, "冷酷追击", 15, 30, 9),
# ]