Find missing dates
Level: Intermediate (score: 3)
Complete get_misssing_dates
that takes an (unordered) sequence of datetime.date
objects. It should determine what the start and end date of this sequence is and return the missing dates.
Here is an example (horizontal scroll code below):
>>> from datetime import date >>> from missing_dates import get_misssing_dates >>> date_range = [date(year=2019, month=2, day=n) for n in range(1, 11, 2)] >>> date_range [datetime.date(2019, 2, 1), datetime.date(2019, 2, 3), datetime.date(2019, 2, 5), datetime.date(2019, 2, 7), datetime.date(2019, 2, 9)] # our function returns the missing dates # = the ones that were not generated in the preceding code >>> sorted(get_misssing_dates(date_range)) [datetime.date(2019, 2, 2), datetime.date(2019, 2, 4), datetime.date(2019, 2, 6), datetime.date(2019, 2, 8)]
Some modules make this fairly easy (hint hint).
Thanks @shravankumar147 for sharing this idea on Twitter last week :)
Good luck and keep calm and code in Python!