Mega Code Archive

 
Categories / Python Tutorial / Function
 

If a function body is a single return expression statement, you may choose to replace the function with the special lambda expres

aList = [1, 2, 3, 4, 5, 6, 7, 8, 9] low = 3 high = 7 print filter(lambda x, l=low, h=high: h>x>l, aList)    # returns: [4, 5, 6]