Ad
Code
Diff
  • # solution WITHOUT using sum(), previous one in lambda form
    sumi = lambda arr: arr.pop(0) + sumi(arr) if arr else 0
    • def sumi(arr):
    • return sum(arr)
    • # solution WITHOUT using sum(), previous one in lambda form
    • sumi = lambda arr: arr.pop(0) + sumi(arr) if arr else 0
Code
Diff
  • 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 :P
    • result = 0
    • for i in arr:
    • result += i
    • return result
    • sumi = lambda arr: arr.pop(0) + sumi(arr) if arr else 0
Code
Diff
  • # this feels stupid, but ok...
    s=sum
    • def sumi(arr):
    • return sum(arr)
    • # this feels stupid, but ok...
    • s=sum
Code
Diff
  • 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
Code
Diff
  • 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