News for hackers. Stuff that matters.
Re:Examples of Incorrect Abstractions in Other Languages by kragen on Wednesday May 20, 2020 @05:19AM (#23244852)
Python sum() can handle summing up other data structures, although, as with foldl, you may have to give it an initial accumulator argument:

    >>> import numpy as np
    >>> xs = np.arange(9).reshape((3,3))
    >>> xs
    array([[0, 1, 2],
           [3, 4, 5],
           [6, 7, 8]])
    >>> sum(xs)  # builtin sum, not numpy sum
    array([ 9, 12, 15])
    >>> sum([[3, 11], [5]], [])
    [3, 11, 5]
    >>> sum([(3, 11), (5,)], ())
    (3, 11, 5)
However, that doesn't work for strings; there's a special-case check for that.

There are no comments on this comment yet.