t445.py 776 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. square = lambda x:x**2
  2. def test1(f,x):
  3. return f(x)
  4. def test2(f,x,y):
  5. return f(x,y)
  6. print square(2), test1(square,2)
  7. print (lambda x:x+5)(4), test1(lambda x:x+5,4)
  8. print (lambda x,y:x-y)(5,4), test2(lambda x,y:x-y,5,4)
  9. print (lambda x,y:x[y]*2)([0,1,2,3,4],4), test2(lambda x,y:x[y]*2,[0,1,2,3,4],4)
  10. def test3(f,g,x,y):
  11. return f(x), f(y), g(x,y), g(f(x),f(y)), f(g(x,y)), f(g(y,x))
  12. f = lambda x:x*27
  13. g = lambda x,y: y+12*x
  14. h = lambda x:f(x)
  15. i = lambda x,y:g(x,y)
  16. print (f(3),f(4),g(3,4),g(f(3),f(4)),f(g(3,4)),f(g(4,3)))
  17. print test3(f,g,3,4)
  18. print test3(h,i,3,4)
  19. j = lambda lst,num,func:lst[func(lst,num)]*(lambda y:10*y)(num)
  20. k = lambda x,y:len(x)-y
  21. def test4(f,x,y,z):
  22. return f(x,y,z)
  23. print j([1,2,3,4,5,6],2,k)
  24. print test4(j,[1,2,3,4,5,6],2,k)