Sum does something like this
def sum(values, start = 0):
total = start
for value in values:
total = total + value
return total
sum([1,2],[3,4])
expands something like [3,4] + 1 + 2
, which you can see tries to add numbers and lists together.
In order to use sum
to produce lists, the values should be a list of lists, whereas start can be just a list. You'll see in your failing examples that the list contains at least some ints, rather then all lists.
The usual case where you might think of using sum with lists is to convert a list of lists into a list
sum([[1,2],[3,4]], []) == [1,2,3,4]
But really you shouldn't do that, as it'll be slow.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…