import sys

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
sum_id = ListHelper.sum(list_skills, lambda item: item.id)
print(sum_id)

sum_cd = ListHelper.sum(list_skills, lambda item: item.cd)
print(sum_cd)

print(sys.path)
print(__name__)
示例#2
0
# 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),
# ]


def demo01(target):
    sum_value = 0
    for item in target:
        # sum_value += item.id
        sum_value += xxx(item)
    return sum_value


def demo02(target):
    sum_value = 0
    for item in target:
        sum_value += item.cd
    return sum_value


def xxx(item):
    return item.id


item = ListHelper.sum(list_skills, lambda item: item.cd)
print(item)