summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLevi Bostian <levi.bostian@gmail.com>2015-10-09 10:04:51 -0500
committerLevi Bostian <levi.bostian@gmail.com>2015-10-09 10:04:51 -0500
commitb5ffe569efc1837935c53cf6658f3a9541072e25 (patch)
treec50bcf66e99a5afe680514a8b99b09274d0a4c00
parentd115a86ac8602c680a059e7a53d227cbccdf157a (diff)
parent777423dcc519b2f25bbcf5238c12ee3a0d4c67c9 (diff)
Merge pull request #1305 from kdelwat/master
[python3/en] Added examples of multiple parameters to higher order functions
-rw-r--r--python.html.markdown3
-rw-r--r--python3.html.markdown3
2 files changed, 6 insertions, 0 deletions
diff --git a/python.html.markdown b/python.html.markdown
index 5572e38e..6cfb5dca 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -473,9 +473,12 @@ add_10(3) # => 13
# There are also anonymous functions
(lambda x: x > 2)(3) # => True
+(lambda x, y: x ** 2 + y ** 2)(2, 1) # => 5
# There are built-in higher order functions
map(add_10, [1, 2, 3]) # => [11, 12, 13]
+map(max, [1, 2, 3], [4, 2, 1]) # => [4, 2, 3]
+
filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
# We can use list comprehensions for nice maps and filters
diff --git a/python3.html.markdown b/python3.html.markdown
index acd6187c..cd1a83cc 100644
--- a/python3.html.markdown
+++ b/python3.html.markdown
@@ -550,10 +550,13 @@ add_10(3) # => 13
# There are also anonymous functions
(lambda x: x > 2)(3) # => True
+(lambda x, y: x ** 2 + y ** 2)(2, 1) # => 5
# TODO - Fix for iterables
# There are built-in higher order functions
map(add_10, [1, 2, 3]) # => [11, 12, 13]
+map(max, [1, 2, 3], [4, 2, 1]) # => [4, 2, 3]
+
filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
# We can use list comprehensions for nice maps and filters