Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. #anonymous value >>> print(2**10) 1024 >>> x = 2**10 #anonymous function >>> (lambda x: x+2)(6) 8 # another method for defining a function >>> plus2 = lambda x: x+2 >>> plus2(6) 8 #writing a function that returns a function >>> def make_pow(n): return lambda x: pow(x,n) >>> sqr = make_pow(2) >>> type(sqr) >>> sqr(10) 100 >>> def make_pow(n): def fixed_exponent_pow(x): return pow(x,n) return fixed_exponent_pow >>> (make_pow(2))(10) 100 >>> cub = make_pow(3) >>> cub(2) 8 #passing a function as a paremetr for another function >>> lst = ["amir","benny", "yael", "michal"] >>> sorted(lst, key=lambda s: len(s)) ['amir', 'yael', 'benny', 'michal'] >>> sorted(lst, key=len) ['amir', 'yael', 'benny', 'michal'] >>> sorted(lst, key = lambda s: s[::-1]) ['michal', 'yael', 'amir', 'benny'] >>> lst_num = ["3","222","11"] >>> sorted(lst_num) ['11', '222', '3'] >>> sorted(lst_num, key = int) ['3', '11', '222'] #writing a function that gets functions as parameters and returns a function >>> def compose(f1,f2): def composed(x): return f1(f2(x)) return composed >>> def compose(f1,f2): return lambda x: f1(f2(x)) >>> h1 = compose(lambda x: x+1, lambda x: 2*x) >>> type(h1) >>> h1(5) 11 >>> h1 . at 0x00000000032952F0> >>> h1 = compose(lambda x: 2*x, lambda x: x+1) >>> h1(5) 12 >>> #running r05_lambda.py file (especially example 4 there) >>> 100 1000 ['4', '11', '222', '3333'] ['11', '222', '3333', '4'] 11 27 [14, 13] 11 14