Skip to content
Advertisement

Python: how to compute date ranges from a list of dates?

I have a list of dates, for example:

JavaScript

How do I find the contiguous date ranges contained within those dates? In the above example, the ranges should be:

JavaScript

Thanks.

Advertisement

Answer

This works, but I’m not happy with it, will work on a cleaner solution an edit the answer. Done, here is a clean, working solution:

JavaScript

And the relative output:

JavaScript
Advertisement