[docs] [issue17815] itertools.combinations example is overly complicated

Theodoros Ikonomou report at bugs.python.org
Mon Apr 22 17:15:08 CEST 2013


New submission from Theodoros Ikonomou:

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

----------
assignee: docs at python
components: Documentation
messages: 187566
nosy: Theodoros.Ikonomou, docs at python
priority: normal
severity: normal
status: open
title: itertools.combinations example is overly complicated
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17815>
_______________________________________


More information about the docs mailing list