I am trying to understand the working of the built-in sum() function, but, the start parameter has evaporated my mind:
a=[[1, 20], [2, 3]] b=[[[[[[1], 2], 3], 4], 5], 6] >>> sum(b,a) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate list (not "int") to list >>> sum(a,b) [[[[[[1], 2], 3], 4], 5], 6, 1, 20, 2, 3]>>> a=[1,2] >>> b=[3,4] >>> sum(a,b) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate list (not "int") to list >>> sum(b,a) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate list (not "int") to list
I am just dumbfounded by this and don't have any idea what is happening. Here is what the python docs have to say: http://docs.python.org/library/functions.html#sum. This does not give any explanation on 'what if the start is not a string and not an integer?'
startargument only for cumulative sums and so type is onlyint. I don't think it's intended for such pathological cases :)sumto numbers :-) you will have less headaches. Make a few explicit constructs if you have to concatenate nested lists - you will have more maintainable code anyway.