Implement a function to calculate the sum of the numerical values in a nested list. For example :

```python
sum_nested([1, [2, [3, [4]]]]) -> 10
```

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Data structures

Complete search

Starter code: def sum_nested(lst):
	

Solutions:
def sum_nested(lst):
	return sum((sum_nested(x) if isinstance(x, list) else x for x in lst))


def sum_nested(lst):
	total = 0
	for ele in lst:
		total += ele if type(ele) != list else sum_nested(ele)
	return total


import re

def sum_nested(lst):
	return sum(map(int, re.findall('\\d+', str(lst))))


def sum_nested(lst):
	return sum(map(sum_nested, lst)) if isinstance(lst, list) else lst


import re

def sum_nested(lst):
	return sum((int(x) for x in re.findall('\\d+', str(lst))))


def sum_nested(lst):
	if not isinstance(lst, list):
		return lst
	return sum((sum_nested(x) for x in lst))


def sum_nested(lst):
	s = 0
	for l in lst:
		if type(l) == list:
			s += sum_nested(l)
		else:
			s += l
	return s


def sum_nested(L):
	if L == []:
		return 0
	if type(L[0]) == int:
		if len(L) == 1:
			return L[0]
		else:
			return L[0] + sum_nested(L[1:])
	else:
		return sum_nested(L[0]) + sum_nested(L[1:])


def sum_nested(L):
	return sum((x if isinstance(x, int) else sum_nested(x) for x in L))


def sum_nested(lst):
	return sum((sum_nested(e) if type(e) is list else e for e in lst))