Quick and Painless Tutorial (cont) # lambda forms add = lambda x: x + x add(2) # returns 4 def make_pow() : return lambda x: x * x make_pow()(3) # returns 9 # functional programming: filter, map, reduce def f(a): return 'b' <= a <= 'c' filter(f, string.split("a b c d")); # return ['b', 'c'] def split(s): return s[0:len(s)/2] map(split, ["aaaaa", "BBBb", "C"]) # returns ['aa', 'BB', ''] def add(x,y): return x + y reduce(add, range(1,10)) # returns 45 # again, using a lambda reduce(lambda x: x + x, range(1,10)) # returns 45 compilers_file = open('tests/compilers.dat', "r") # get a list of compilers (strings), stripped of whitespaces compilers = [string.strip(z) for z in compilers_file.readlines()]