#!/usr/bin/python3 # -*- coding: utf-8 -*- """ Sum more recursion... """ from typing import List # %% Sum Iterative def sum_loop(my_list: List[int]) -> int: """ Iterative sum """ accum_sum = 0 # Add every number in the list. for i in range(0, len(my_list)): accum_sum = accum_sum + my_list[i] # Return the sum. return accum_sum print(sum_loop([5, 7, 3, 8, 10])) # %% Sum Recursive def sum_rec(my_list: List[int]) -> int: """ Recursive sum """ if len(my_list) == 1: return my_list[0] else: return my_list[0] + sum_rec(my_list[1:]) print(sum_rec([5, 7, 3, 8, 10]))