# [Python-ideas] Set starting point for itertools.product()

Jonathan Fine jfine2358 at gmail.com
Thu Oct 25 04:03:42 EDT 2018

```I see three issues emerging from Ronie's post.

The first issue. Each combinatorial iterator, such as
itertools.product, has an internal state. This internal state,
roughly, is 'where am I'? For the product of three tuples, the
internal state is the value of (i, j, k), the indexes into the tuples.

The first issue is: how to set the internal state of a combinatorial
iterator? And should this be added to the standard library?

The second issue. Again, it's about combinatorial iterators. Here's an
example. By using enumerate(combinations('ABCD', 2)) we set up a
bijection between range(0, 4 * 3 // 2) and the length two subsets of
set('ABCD'). When and how should this bijection be made available.

The third issue is solving the specific date and time problem he
provides. Because of the complexities of date and time, this is I
think best done using the datetime module.

For me, something like the below (not tested) is the obvious thing to try.

def my_moments(start, step):
i = 0
while True:
value = start + i * step
yield value
i = i + 1

Here, start is to be a datetime, and step a timedelta. And instead of
yielding the value as is, convert it if you wish to a tuple of (year,
month, day, hour, minute, second).

Ronie. Does this solve your problem? And if not, why not?

--
Jonathan
```

More information about the Python-ideas mailing list