def recsum(x):
"""
Given either a list or a number, either returns the number or
computes the sum of all the elements in the list (including elements
inside other lists).
"""
if type(x) != list:
return x
else:
total = 0
for y in x:
total = total + recsum(y)
return total
if __name__ == "__main__":
rlist = [1,2,3]
print "sum of list", rlist, "is: ", recsum(rlist)
rlist = [1,2,[3,4,5]]
print "sum of list", rlist, "is: ", recsum(rlist)
rlist = [[1,[4,5]],-4,[[6,[7],[9,10]],0]]
print "sum of list", rlist, "is: ", recsum(rlist)