I was wondering if there was a simple alternative to lambda in my code.
def add_attack(self, attack_name):
if attack_name in self.known_attacks and attack_name not in self.attacks:
try:
assert(len(self.attacks) < 4)
self.attacks[attack_name] = self.known_attacks.get(attack_name)
return True
except:
#find the min value of self.attacks
minval = min(self.attacks.keys(), key=(lambda k: self.attacks[k]))
for keys, values in self.attacks.items():
if self.attacks[minval] == values and min(minval, keys) == keys:
minval = keys
del self.attacks[minval]
self.attacks[attack_name] = self.known_attacks.get(attack_name)
return True
else:
return False
I'm still learning python, and the lambda function is throwing me off since I haven't learned that much about it yet. Instead of using lambda, can someone help me out with another function to replace lambda? Thanks!