[Python-ideas] Set starting point for itertools.product()
Ronie Martinez
ronmarti18 at gmail.com
Thu Oct 25 03:07:15 EDT 2018
Hi another Steve,
Your code will not work! You are skipping the other values below it. When,
let's say, the minute value reaches 59, the next iterator should return 0.
In your code, it will not. It will start with 5. That is not how an
odometer wheel works.
Best Regards,
Ronie
On Thu, Oct 25, 2018 at 2:59 PM Stephen J. Turnbull <
turnbull.stephen.fw at u.tsukuba.ac.jp> wrote:
> Ronie Martinez writes:
>
> > 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
>
> I don't understand the issue. Doesn't
>
> def make_odometer(year, month, day, hour, minute, second):
> return itertools.product(
> range(year, 10_000),
> range(month, 13),
> range(day, 31),
> range(hour, 24),
> range(minute, 60),
> range(second, 61) # leap seconds!
> )
>
> def main():
> datetime_of_interest = (2050, 6, 15, 10, 5, 0)
>
> datetime_odometer = make_odometer(*datetime_of_interest)
>
> do what you want? If you have a task where that *doesn't* do what's
> needed, eg, where the "odometer wheels" are an iterated function
> system, I don't see any way to avoid the problem. If you have some
> range-like object that doesn't support starting values, you need to
> fix that or there's nothing that could be done about it in itertools.
>
> (Yet Another) Steve
>
> --
> Associate Professor Division of Policy and Planning Science
> http://turnbull.sk.tsukuba.ac.jp/ Faculty of Systems and Information
> Email: turnbull at sk.tsukuba.ac.jp University of Tsukuba
> Tel: 029-853-5175 Tennodai 1-1-1, Tsukuba 305-8573 JAPAN
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20181025/c55c8e06/attachment.html>
More information about the Python-ideas
mailing list