Skip to content

Commit

Permalink
Add examples of higher-order functions taking multiple arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelwat committed Oct 7, 2015
1 parent 6ac7368 commit 777423d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions python3.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 777423d

Please sign in to comment.