Hi Steve, Here is an example: import itertools import time def main(): 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 break if __name__ == '__main__': start = time.time() main() 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. Regards, Ronie On Thu, Oct 25, 2018 at 1:49 PM Steven D'Aprano <steve@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?
-- Steve _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/