I need to iterate through a list of date values in Python and get two dates at a time.
Something along the lines of
import datetime
listdates=[datetime.date(2022, 2, 10),datetime.date(2022, 2, 11),datetime.date(2022, 2, 12),datetime.date(2022, 2, 13),datetime.date(2022, 2, 14)]
for a in listdates:
print(a,next(a))
The problem is that Python doesn't seem to support iterating through dates like this (see error below)
TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_1868/3080882783.py in <module>
2
3 for a in listdates:
----> 4 print(a,next(a))
TypeError: 'datetime.date' object is not an iterator
I'm sure there is something I am missing here, but I need these in date format because I need to pass the date values to a different procedure.
Do I need to do something like convert the values to text and back to dates again? Seems like an awful hack.
Any help would be very much appreciated