This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: itertools.combinations example is overly complicated
Type: behavior Stage:
Components: Documentation Versions: Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 2.7, Python 2.6
process
Status: closed Resolution: postponed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Theodoros.Ikonomou, docs@python
Priority: normal Keywords:

Created on 2013-04-22 15:15 by Theodoros.Ikonomou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (1)
msg187566 - (view) Author: Theodoros Ikonomou (Theodoros.Ikonomou) Date: 2013-04-22 15:15
I find the code presented as equivalent for itertools.combinations is overly complex.
I think we can change it to something easier like the following:

def combinations(iterable, r):
    i, size = 0, len(iterable)
    while i + r - 1 < size:
        subindex = i+1
        while subindex + r - 2 < size:
                yield (iterable[i],) + tuple(iterable[subindex:subindex+r-1])
                subindex += r - 1
        i += 1
History
Date User Action Args
2022-04-11 14:57:44adminsetgithub: 62015
2013-04-22 15:30:52Theodoros.Ikonomousetstatus: open -> closed
resolution: postponed
2013-04-22 15:15:08Theodoros.Ikonomoucreate