Ad
  • Custom User Avatar

    Also for the python one. I think this issue is in general.

  • Custom User Avatar

    Thank you so much. It was so nice to have a explainaton like this especially the machine one. You are awesome. (Y)

  • Custom User Avatar

    If you would like to write a function that takes a value x and returns x + 1, you might write

    def foo(x): 
        return x + 1
    

    in python. With lambda expressions, one may instead write

    foo = lambda x: x + 1
    

    Perhaps it is easier to understand when one imagines foo is a machine, which eats x and spits x + 1. The keyword lambda is the common 'command' or 'tag' for such machines.

    In this kata, we are expected to parse a list and return the max and min. Since functions max and min operate on lists, we call it as max(l) and min(l). The answer is expected as a list, so we write it as [min(l), max(l)]. The argument l should be also defined --- that is the purpose of the lambda l: part. The things after the '=' define a function (but they do not give it a name). Then we use the operator '=' to name it as min_max and everything is fine.

    EDITS

    1. Correct the explanation where subject and verb do not agree in numbers. Sorry for the mistakes, but my mother tongue is not English.

    2. Rephrase some badly-written sentences.

  • Custom User Avatar

    Can you please explain me how this works?