[Python-ideas] Set starting point for itertools.product()
ronmarti18 at gmail.com
Thu Oct 25 02:31:05 EDT 2018
Here is an example:
datetime_odometer = itertools.product(
range(2018, 10_000), # year
range(1, 13), # month
range(1, 31), # days
range(0, 24), # hours
range(0, 60), # minutes
range(0, 60) # seconds
datetime_of_interest = (2050, 6, 15, 10, 5, 0)
for i in datetime_odometer:
if i == datetime_of_interest: # target start time
if __name__ == '__main__':
start = time.time()
duration = time.time() - start
print(duration, 'seconds') # 91.9426908493042 seconds
It took 92 seconds to get to the target start time. It does not only apply
to datetimes but for other purposes that uses "odometer-like" patterns.
I don't have any propose solution for now, but I guess adding this feature
within itertools will come in handy.
On Thu, Oct 25, 2018 at 1:49 PM Steven D'Aprano <steve at pearwood.info> wrote:
> On Thu, Oct 25, 2018 at 11:47:18AM +0800, Ronie Martinez wrote:
> > Hi,
> > My idea is to set the starting point for itertools.product()
> > <https://docs.python.org/3.6/library/itertools.html#itertools.product>
> > since it becomes very slow if the point of interest is in the middle. For
> > example when working with datetime tuples with seconds resolution (worst
> > case, milli/microseconds), you need to skip a lot of items.
> I don't understand what you mean by "skip a lot of items" or why this
> applies to datetime tuples.
> Can you give a SHORT and SIMPLE example, showing both the existing
> solution and your proposed solution?
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas