[issue40225] recursive call within generator expression is O(depth)

brendon zhang report at bugs.python.org
Thu Apr 9 07:15:03 EDT 2020


brendon zhang <brendon-zhang at hotmail.com> added the comment:

update 2:
This affects ALL functions which exhaust a generator expression. If that generator expression makes a recursive call, then the cost of evaluating it is O(depth), when it should be only O(1).

You can see demonstrate that this doesn't just affect builtins, by replacing max() with a custom implementation such as,

def custommax(it):
    best = -9999999
    for x in it:
        if x > best:
            best = x
    return best

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40225>
_______________________________________


More information about the Python-bugs-list mailing list