Earlier quoted context omitted.
The q in your latter example is the same complexity in my book as a dense Python list comprehension. Could be worse.
The equivalent python is: mss = lambda x: max(scan(lambda a,b: max(0,a+b),0,x)) assuming a definition "scan" (which is like "reduce", except it gives you all intermediate values), an example of which is: def scan(f,x0,x): r = [x0] for x1 in x: x0 = f(x0, x1) r.append(x0) return r Note that the K is idiomatic whereas the python is (arguably) not. Of course, it could be worse; the advantage is that, much like math, the…
def scan(f, iterator, initial=0):
yield initial
yield from scan(f, iterator, f(initial, next(iterator)))
Even with python2, you could make a non-recursive version that'd be still shorter than your scan and faster. Alternatively, you could pair a coroutine with that reduce function....But always be suspect of your code if you are iterating and appending to a list. Likely there is a much better way.