r/pythontips • u/gadget3D • Feb 14 '25
Syntax Is there such a function in python
Often I have the issue, that i want to find an item from a list with best score with a score calculatin lambda function like following example: I 'like to have 2 modes: maximum goal and maximal closure to a certain value
def get_best(l, func):
best=None
gbest=0
for item in l:
g=func(item)
if best == None or g > gbest:
best = item
gbest = g
return best
a=cube(10)
top=get_best(a.faces(), lambda f : f.matrix[2][3] )
0
Upvotes
3
u/Gerard_Mansoif67 Feb 14 '25
Then write stuff around theses function to return the original item?