x = [1, 2, 3, 4]; print x; // [1, 2, 3, 4]
y = x.append(5);
print y; // [1, 2, 3, 4, 5] print x; // [1, 2, 3, 4]
def make_adder(x): # close over x return lambda y: x + y add5 = make_adder(5) # I am returning a function here add5(10) # 15
###
["Church","Turing","Gödel"].sort(key=lower)
nums = [77, 45, 2, 98, -12] # square all numbers nums2 = map(square, nums) # [5929, 2025, 4, 9604, 144] # keep only > 1000 print filter(lambda n: n > 1000, nums2)
[5929, 2025, 9604]
square(5) == 25 # a pure function
square(5) + square(5) + square(5)
# compiler can optimize this as
25 + 25 + 25