diff options
Diffstat (limited to 'python.html.markdown')
-rw-r--r-- | python.html.markdown | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/python.html.markdown b/python.html.markdown index 352f7349..6cfb5dca 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -198,7 +198,7 @@ li[::-1] # => [3, 4, 2, 1] # Remove arbitrary elements from a list with "del" del li[2] # li is now [1, 2, 3] -r + # You can add lists li + other_li # => [1, 2, 3, 4, 5, 6] # Note: values for li and for other_li are not modified. @@ -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 |