In python 2.6, I want to do:
f = lambda x: if x==2 print x else raise Exception() f(2) #should print \"2\" f(3) #should throw an exception <
Following sample code works for me. Not sure if it directly relates to this question, but hope it helps in some other cases.
a = ''.join(map(lambda x: str(x*2) if x%2==0 else "", range(10)))