return count def delete02(): count = 0 for i in range(len(list_employee)-1,-1,-1): if list_employee[i].did == 9005: del list_employee[i] count += 1 return count """ # 参数是列表中的每个元素 # count = IterableHelper.delete_all(list_employee,lambda emp:emp.money < 15000) # print(count) count = IterableHelper.delete_all(list_employee, lambda item: item.did == 9005) print(count) # def get_max01(): # max_value = list_employee[0] # for i in range(1, len(list_employee)): # if max_value.money < list_employee[i].money: # max_value = list_employee[i] # return max_value # # def get_max02(): # max_value = list_employee[0] # for i in range(1, len(list_employee)): # if max_value.eid < list_employee[i].eid: # max_value = list_employee[i] # return max_value
self.price = price self.color = color list_phones = [ Phone("华为1", 5999, "蓝色"), Phone("华为2", 6999, "红色"), Phone("苹果1", 9999, "金色"), Phone("苹果2", 7999, "白色"), Phone("三星2", 4999, "白色"), ] def delete_all01(): for i in range(len(list_phones) - 1, -1, -1): if list_phones[i].color == "蓝色": del list_phones[i] def delete_all02(): for i in range(len(list_phones) - 1, -1, -1): if list_phones[i].price < 7000: del list_phones[i] # def condtion01(phone): # return phone.color == "蓝色" IterableHelper.delete_all(list_phones, lambda phone: phone.color == "蓝色") for item in list_phones: print(item.__dict__)
# 员工列表 list_employees = [ Employee(1001, 9002, "师父", 60000), Employee(1002, 9001, "孙悟空", 50000), Employee(1003, 9002, "猪八戒", 20000), Employee(1004, 9001, "沙僧", 30000), Employee(1005, 9001, "小白龙", 15000), ] """ def delete_all01(): count = 0 for i in range(len(list_employees)-1,-1,-1): if list_employees[i].money > 20000: del list_employees[i] count +=1 return count def delete_all02(): count = 0 for i in range(len(list_employees) - 1, -1, -1): if list_employees[i].did == 9001: del list_employees[i] count += 1 return count """ print(IterableHelper.delete_all(list_employees, lambda item: item.did == 9001)) print(list_employees)