Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fact = lambda x: 1 if x == 0 else x * fact(x-1)
- fact = lambda x: x == 0 and 1 or x * fact(x-1)
- >>> map(lambda n: (lambda f, *a: f(f, *a))(lambda rec, n: 1 if n == 0 else n*rec(rec, n-1), n), range(10))
- [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
- # helper function
- def recursive(f, *p, **kw):
- return f(f, *p, **kw)
- def fib(n):
- # The rec parameter will be the lambda function itself
- return recursive((lambda rec, n: rec(rec, n-1) + rec(rec, n-2) if n>1 else 1), n)
- # using map since we already started to do black functional programming magic
- print map(fib, range(10))
- (lambda v: (lambda n: n * __import__('types').FunctionType(
- __import__('inspect').stack()[0][0].f_code,
- dict(__import__=__import__, dict=dict)
- )(n - 1) if n > 1 else 1)(v))(5)
Add Comment
Please, Sign In to add comment