Give a method that sums all the numbers in a list. The method should be able to skip elements that are not numbers. So, sum([1, 2, 3]) should be
list
sum([1, 2, 3])
def filtersum(L): if not L: return 0 if not isinstance(L[0], int): return filtersum(L[1:]) return L[0] + filtersum(L[1:])
Output:
In [28]: filtersum([1,2,3]) Out[28]: 6 In [29]: filtersum([1,'A', 2,3]) Out[29]: 6