Skip to content

Using the function argument of itertools.accumulate() gets error against the doc #135282

Open
@hyperkai

Description

@hyperkai

Bug report

Bug description:

The doc of itertools.accumulate() says the 2nd parameter is function as shown below:

itertools.accumulate(iterable[, function, *, initial=None])

But using function argument gets the error against the doc as shown below:

from itertools import accumulate
from operator import mul
                                            # ↓↓↓↓↓↓↓↓
for x in accumulate(iterable=[1, 2, 3, 4, 5], function=mul):
    print(x)
# TypeError: 'function' is an invalid keyword argument for accumulate()

So, I used func argument, then it works as shown below:

from itertools import accumulate
from operator import mul
                                            # ↓↓↓↓
for x in accumulate(iterable=[1, 2, 3, 4, 5], func=mul):
    print(x)
# 1
# 2
# 6
# 24
# 120

CPython versions tested on:

3.13

Operating systems tested on:

Windows

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions