Comment by vova_hn2

6 hours ago

Of course it is also possible to just create a temporary list and throw it away immediately:

    lst = [1, 2, 3]
    acc = 0
    [acc := acc + item for item in lst]  # this is the actual reduce
    print(acc)

This way you wouldn't need to take that weird function from Itertools Recipes.

It should be possible to optimize away the creation of the temporary list and avoid wasting CPU and memory on it. But I don't know if CPython actually has this optimization, that's why I didn't mention it initially. I would love someone more knowledgeable in CPython internals to tell me how this would work.