On Wed, 9 Feb 2022 at 01:00, Aman Pandey <amanpandey5...@gmail.com> wrote:
>
> I wanted to generate all the dates between two date ranges for which I was 
> using count function in the itertools and to my surprise count function 
> doesn't support datetime operation.
>
>  For example
> >import datetime
> >from itertools import count
> >count(datetime.date.today(), datetime.timedelta(1))
>
> Why is count function only limited to numbers shouldn't we make it generic 
> that it should support operation like datetime where addition between the 
> objects is possible.
>
> Would like to hear thoughts from you people.

This sounds like a perfect place for a custom generator function.

def timecount(start, **delta):
    delta = datetime.timedelta(**delta)
    while True:
        yield start
        start += delta

timecount(datetime.date.today(), days=1)

The default itertools.count is highly optimized for its job, but when
you need flexibility, it's easy enough to handroll something to your
needs.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/QNRDC4LY5VRSJTYGGVBXCLZJI6FLLMG6/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to