The Python max function accepts the key= parameter for the measure function.
data = {1: 25, 0: 75} def keymeasure(key): return data[key] and key print max(data, key=keymeasure)
Using the built-in lambda for the same effect and the same local variable binding:
print max(data, key=(lambda k: data[k] and k))
the last alternative to binding in a local variable var to an anonymous key function
print max(data, key=(lambda k, mapping=data: mapping[k] and k))
u0b34a0f6ae
source share