Move History

Fork Selected
  • Code
    from functools import reduce
    prod =lambda n:reduce(lambda x,y:x*y,n if n else[0])
    Test Cases
    # TODO Write tests
    import solution # or from solution import example
    
    # test.assert_equals(actual, expected, [optional] message)
    @test.describe("Simple tests")
    def test_group():
        @test.it("Short lists")
        def test_case():
            test.assert_equals(prod([1,1]), 1)
            test.assert_equals(prod([]), 0)
            test.assert_equals(prod(range(1,10)), 362880)
    
  • Code
    • from itertools import product
    • def prod(n):
    • if not n:return 0
    • n = n[-1]
    • fact = lambda x: x if x <= 2 else x*fact(x-1)
    • return fact(n)
    • from functools import reduce
    • prod =lambda n:reduce(lambda x,y:x*y,n if n else[0])