Python Functional Stuff
A crash course.
Python has First Class Functions
def create_adder(x):
def adder(y):
return x + y
return adder
>>> add_10 = create_adder(10)
>>> add_10(3)
13
Python has Anonymous Functions
(lambda x: x > 2)(3) # => True
Python has Built-in Higher Order Functions
map(add_10, [1, 2, 3]) # => [11, 12, 13]
filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
Written by bt3gl
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Related Tags
#python
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#