-
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) .describe("Simple tests") def test_group(): .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)
Output:
-
Code from itertools import productdef prod(n):if not n:return 0n = 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])
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}