Enemy(104, "芳芳", 17, 30, 9) ] # 1. 查找所有死人. for item in ListHelper.find_all(L, lambda enemy: enemy.hp == 0): print(item) print() # 2. 查找编号是101的敌人 target = ListHelper.first(L, lambda enemy: enemy.id == 101) print(target) print() # 3. 查找所有活人. for item in ListHelper.find_all(L, lambda enemy: enemy.hp > 0): print(item) print() # 4. 计算所有敌人攻击力总和 result = ListHelper.sum(L, lambda enemy: enemy.atk) print(result) print() # 5. 查找所有攻击速度在5--10之间的敌人 for item in ListHelper.find_all(L, lambda enemy: 5 <= enemy.atk_speed <= 10): print(item) print() # 6. 查找所有敌人的姓名 for item in ListHelper.select(L, lambda enemy: enemy.name): print(item)
Enemy(103, "qtx", 800, 1000, 50), Enemy(104, "吕泽玛利亚", 0, 300, 2), Enemy(105, "赵金多", 500, 900, 10), ] # 1. 查找所有死人. 10:44 for item in ListHelper.find_all(list01, lambda e: e.hp == 0): print(item.name) # 2. 查找编号是101的敌人 result = ListHelper.first(list01, lambda e: e.id == 101) print(result.name) # 3. 查找所有活人. for item in ListHelper.find_all(list01, lambda e: e.hp > 0): print(item.name) # 4. 计算所有敌人攻击力总和 result = ListHelper.sum(list01, lambda e: e.atk) print(result) # 5. 查找所有攻击速度在5--10之间的敌人 for item in ListHelper.find_all(list01, lambda e: 5 <= e.atk_speed <= 10): print(item.name) # 6. 查找所有敌人的姓名 # for item in ListHelper.select(list01,lambda e:e.name): # print(item) # 结果是生成器对象 result = ListHelper.select(list01, lambda e: e.name) # 生成器 --> 列表 result = list(result) for item in result[1:3]: print(item)