#! /usr/bin/env python

# ------------------------------------------------------------------------------
# @author Billy Wilson Arante
# @modified 1/16/2016 PHT
#
# @copyright
# Computer Science Circles
# http://cscircles.cemc.uwaterloo.ca/16-recursion/#pybox10
#
# @description
# Sum up the items of nested lists.
# ------------------------------------------------------------------------------

def nestedlst_sum(nested_lst):
    if isinstance(nested_lst, int): # nested_lst is int
        return nested_lst # Returns an int

    sum = 0
    for i in range(0, len(nested_lst)): # nested_lst is list
        sum = sum + nestedlst_sum(nested_lst[i])

    return sum

# Testing use cases
# -----------------
def test():
    # Test 1
    print(nestedlst_sum([1, 2, 3])) # Sum is 6

    # Test 2
    print(nestedlst_sum([[1, 10], [100, 10]])) # Sum is 121

    # Test 3
    print(nestedlst_sum([[3], [[5, [4]], 2, 1]])) # Sum is 15

    # Test 4
    print(nestedlst_sum([[[[54238]]]])) # Sum is 54238

    # Test 5
    print(nestedlst_sum([1, [2, [3, [4, [5]]]]])) # Sum is 15

if __name__ == "__main__":
    test()
