Simple recursive sum function | what's the cause of the weird behaviour?
__peter__ at web.de
Sat Jul 6 15:19:30 CEST 2013
Russel Walker wrote:
> Since I've already wasted a thread I might as well...
> Does this serve as an acceptable solution?
> def supersum(sequence, start=0):
> result = type(start)()
> for item in sequence:
> result += supersum(item, start)
> result += item
> return result
That depends on what is an acceptable result ;)
>>> supersum([2, 3], 1)
>>> supersum([, ["abc"]], )
[1, 'a', 'b', 'c']
More information about the Python-list