[フレーム]
Last Updated: February 25, 2016
·
609
· bt3gl

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]

AltStyle によって変換されたページ (->オリジナル) /