[issue39755] Change example of itertools.product

Mark Bell report at bugs.python.org
Tue Feb 25 18:53:56 EST 2020


New submission from Mark Bell <mark00bell at googlemail.com>:

The documentation for itertools.product at: https://docs.python.org/3/library/itertools.html#itertools.product
currently says that:

    For example, product(A, B) returns the same as ((x,y) for x in A for y in B)

While this is broadly correct, since product first converts its arguments to tuples, this is not true if A or B are infinite iterables. For example, when A = itertools.count() and B = range(2) then the former runs forever using infinite memory, whereas the latter returns the lazy generator immediately for use.

Would it be clearer / more correct to instead say:

    For example, product(A, B) returns the same as ((x,y) for x in tuple(A) for y in tuple(B))

----------
assignee: docs at python
components: Documentation
messages: 362672
nosy: Mark.Bell, docs at python
priority: normal
severity: normal
status: open
title: Change example of itertools.product
versions: Python 3.5

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


More information about the Python-bugs-list mailing list