I have a list which contains various nested lists, themselves always holding two arrow objects constituting date ranges from a start date (index 0) to an end date (index 1).
I aim to merge any overlapping lists, then sorting them chronologically.
import arrow
date_range_lst = [
[arrow.get("2020-01-05"), arrow.get("2020-02-26")],
[arrow.get("2020-02-07"), arrow.get("2020-02-08")],
[arrow.get("2020-05-16"), arrow.get("2020-07-28")],
[arrow.get("2020-02-25"), arrow.get("2020-03-19")],
[arrow.get("2020-05-15"), arrow.get("2020-05-16")],
[arrow.get("2021-03-01"), arrow.get("2021-04-01")],
[arrow.get("2021-05-05"), arrow.get("2021-08-08")],
]
date_range_merged_lst = []
# Code here
print(date_range_merged_lst)
For the above example, the intended output would look like this (done manually, but should be correct):
[[<Arrow [2020-01-05T00:00:00+00:00]>, <Arrow [2020-03-19T00:00:00+00:00]>],
[<Arrow [2020-05-15T00:00:00+00:00]>, <Arrow [2020-07-28T00:00:00+00:00]>],
[<Arrow [2021-03-01T00:00:00+00:00]>, <Arrow [2021-04-01T00:00:00+00:00]>],
[<Arrow [2021-05-05T00:00:00+00:00]>, <Arrow [2021-08-08T00:00:00+00:00]>]]