Comment

Comment by flavio81

Yes but lambda allows some versatility, for example (excuse my Python, it is a bit rusty):

    formulas = {
        'sum': lambda x,y: x+y,
        'subst': lambda x,y: x-y,
        'mult': lambda x,y: x*y,
        'pow': lambda x,y: x**y
        }

    def apply_operator(operation_name, x, y):
        operation=formulas[operation_name]
        return operation(x,y)

Using "def"s there would kill readability and easiness of coding.
parent flavio81 9 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton