Issue 17815: itertools.combinations example is overly complicated (original) (raw)
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