From 2e9f341251477ddba7f126d0eba1ef55b761893f Mon Sep 17 00:00:00 2001 From: Hamza Muric Date: Tue, 15 Jan 2019 23:08:27 +0100 Subject: [PATCH] Add lambda as function parameter (#26371) Added lambda passing as an argument to function, --- guide/english/python/lambda-expressions/index.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/guide/english/python/lambda-expressions/index.md b/guide/english/python/lambda-expressions/index.md index e6a35a564c7..14a10b763d1 100644 --- a/guide/english/python/lambda-expressions/index.md +++ b/guide/english/python/lambda-expressions/index.md @@ -46,6 +46,16 @@ lambda_func(4) # Returns True (4**2 = 16, which is >= 10) my_dict = {"A": 1, "B": 2, "C": 3} sorted(my_dict, key=lambda x: my_dict[x]%3) # Returns ['C', 'A', 'B'] # sort dict by the values % 3 (remainders from division by 3) ``` + +### Passing lambda as fuction parameter +```py +def apply(x, y, fun): + return fun(x, y) + +res = apply(3, 5, lambda x, y: x + y) +print(res) # Output: 8 +``` + ### Use-case Let's say you want to filter out odd numbers from a `list`. You could use a `for` loop: