Allow the starting indices of itertools.product to be specified

The productobject created by itertools.product works by maintaining a tuple of indices to determine the next element the product should produce as it is iterated over. This starts as an array of 0’s and after each element is produced by the iterable it is incremented.

Currently indices is initialised to an array of 0’s when the product is created. If the initial value of this array was accessible via a keyword argument to the constructor then it would be possible to start the product in the middle of the sequence. For example

>>> list(itertools.product('ABC', 'XYZ', indices=(1, 1)))
[('B', 'Y'), ('B', 'Z'), ('C', 'X'), ('C', 'Y'), ('C', 'Z')]

Can’t you just rotate the argument tuples?

1 Like

Yes, of course! That’s a great idea. Thanks.