Note from the author: This is very inefficient. But fun, because monoids are awesome. It's not appropriate for production Python code.
>>> lxss = [[1, 2, 3], [4, 5, 6], [7], [8, 9]]
>>> sum(lxss, [])
[1, 2, 3, 4, 5, 6, 7, 8, 9]
This justsum sums the elements of iterable passed in the first argumentiterable xss, treatingand uses the second argument as the initial value of[] for the sum. (if not given,The default initial value is 0, which is used instead and this case will give you an error)not a list.)
Because you are summing nested lists, you actually get [1,3]+[2,4] as a result of sum([[1,3],[2,4]],[]), which is equal to [1,3,2,4].
Note that only works on lists of lists. For lists of lists of lists, you'll need another solution.