sumi = lambda arr: arr.pop(0) + sumi(arr) if arr else 0
def sum(arr):#if not arr check is not neccessary, result stays at 0 :Presult = 0for i in arr:result += ireturn result- sumi = lambda arr: arr.pop(0) + sumi(arr) if arr else 0
import codewars_test as test # TODO Write tests from solution import sumi # test.assert_equals(actual, expected, [optional] message) @test.describe("Example tests") def test_group(): @test.it("Basic tests") def test_case(): test.assert_equals(sumi([]), 0) test.assert_equals(sumi([1]), 1) test.assert_equals(sumi([1,2,3,4,5,-9]), 6) test.assert_equals(sumi([1,2,3,2,1,-10]), -1)
- import codewars_test as test
- # TODO Write tests
from solution import sum- from solution import sumi
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example tests")
- def test_group():
- @test.it("Basic tests")
- def test_case():
test.assert_equals(sum([1]), 1)test.assert_equals(sum([1,2,3]), 6)- test.assert_equals(sumi([]), 0)
- test.assert_equals(sumi([1]), 1)
- test.assert_equals(sumi([1,2,3,4,5,-9]), 6)
- test.assert_equals(sumi([1,2,3,2,1,-10]), -1)
# this feels stupid, but ok... s=sum
def sumi(arr):return sum(arr)- # this feels stupid, but ok...
- s=sum
import codewars_test as test # TODO Write tests from solution import s # test.assert_equals(actual, expected, [optional] message) @test.describe("Example tests") def test_group(): @test.it("Basic tests") def test_case(): test.assert_equals(s([]), 0) test.assert_equals(s([1]), 1) test.assert_equals(s([1,2,3]), 6) test.assert_equals(s([1,2,3,1,2,3]), 12) test.assert_equals(s([1,2,3,-1,-2,-3]), 0) test.assert_equals(s([10**7,1,2,3,1,2,3,-10**7]), 12)
- import codewars_test as test
- # TODO Write tests
from solution import sumi- from solution import s
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example tests")
- def test_group():
- @test.it("Basic tests")
- def test_case():
test.assert_equals(sumi([]), 0)test.assert_equals(sumi([1]), 1)test.assert_equals(sumi([1,2,3]), 6)test.assert_equals(sumi([1,2,3,1,2,3]), 12)test.assert_equals(sumi([1,2,3,-1,-2,-3]), 0)test.assert_equals(sumi([10**7,1,2,3,1,2,3,-10**7]), 12)- test.assert_equals(s([]), 0)
- test.assert_equals(s([1]), 1)
- test.assert_equals(s([1,2,3]), 6)
- test.assert_equals(s([1,2,3,1,2,3]), 12)
- test.assert_equals(s([1,2,3,-1,-2,-3]), 0)
- test.assert_equals(s([10**7,1,2,3,1,2,3,-10**7]), 12)
def sumi(arr): # parity: sum([]) == 0 try: return arr.pop(0) + sumi(arr) except: return 0
sum_integers = lambda arr, r=0: [r := r + n for n in arr][-1]- def sumi(arr): # parity: sum([]) == 0
- try: return arr.pop(0) + sumi(arr)
- except: return 0
import codewars_test as test # TODO Write tests from solution import sumi # test.assert_equals(actual, expected, [optional] message) @test.describe("Example tests") def test_group(): @test.it("Basic tests") def test_case(): test.assert_equals(sumi([]), 0) test.assert_equals(sumi([1]), 1) test.assert_equals(sumi([1,2,3]), 6) test.assert_equals(sumi([1,2,3,1,2,3]), 12) test.assert_equals(sumi([1,2,3,-1,-2,-3]), 0) test.assert_equals(sumi([10**7,1,2,3,1,2,3,-10**7]), 12)
- import codewars_test as test
- # TODO Write tests
from solution import sum_integers- from solution import sumi
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example tests")
- def test_group():
- @test.it("Basic tests")
- def test_case():
test.assert_equals(sum([1]), 1)test.assert_equals(sum([1,2,3]), 6)test.assert_equals(sum([1,2,3,1,2,3]), 12)test.assert_equals(sum([1,2,3,-1,-2,-3]), 0)test.assert_equals(sum_integers([10**7,1,2,3,1,2,3,-10**7]), 12)- test.assert_equals(sumi([]), 0)
- test.assert_equals(sumi([1]), 1)
- test.assert_equals(sumi([1,2,3]), 6)
- test.assert_equals(sumi([1,2,3,1,2,3]), 12)
- test.assert_equals(sumi([1,2,3,-1,-2,-3]), 0)
- test.assert_equals(sumi([10**7,1,2,3,1,2,3,-10**7]), 12)
def sum_integers(arr): result = 0 [result := result + n for n in arr] return result
- def sum_integers(arr):
- result = 0
for i in range(min(arr), max(arr) + 1):result += i * arr.count(i)- [result := result + n for n in arr]
- return result
import codewars_test as test # TODO Write tests from solution import sum_integers # test.assert_equals(actual, expected, [optional] message) @test.describe("Example tests") def test_group(): @test.it("Basic tests") def test_case(): test.assert_equals(sum([1]), 1) test.assert_equals(sum([1,2,3]), 6) test.assert_equals(sum([1,2,3,1,2,3]), 12) test.assert_equals(sum([1,2,3,-1,-2,-3]), 0) test.assert_equals(sum_integers([10**7,1,2,3,1,2,3,-10**7]), 12)
- import codewars_test as test
- # TODO Write tests
- from solution import sum_integers
- # test.assert_equals(actual, expected, [optional] message)
- @test.describe("Example tests")
- def test_group():
- @test.it("Basic tests")
- def test_case():
- test.assert_equals(sum([1]), 1)
- test.assert_equals(sum([1,2,3]), 6)
- test.assert_equals(sum([1,2,3,1,2,3]), 12)
- test.assert_equals(sum([1,2,3,-1,-2,-3]), 0)
- test.assert_equals(sum_integers([10**7,1,2,3,1,2,3,-10**7]), 12)