I have a list of several consecutive months, always including the current month. For example, as I write this it is April 2020, so a valid list could be any of the following:
example1 = ["January", "February", "March", "April", "May"]
example2 = ["December", "January", "February", "March", "April"]
example3 = ["April", "May", "June", "July", "August", "September", "October", "November", "December", "January", "February"]
What's the best way to write a Python function which, given a list like this, would return a corresponding list of years, pivoting around the current month being the current year. For example:
f(example1) = [2020, 2020, 2020, 2020, 2020]
f(example2) = [2019, 2020, 2020, 2020, 2020]
f(example3) = [2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2021, 2021]
The best I can think of is partition the original list by the current month, then loop in each direction while also keeping track of the year, then put the two resulting lists together. But this is way too much looping. Is there a more elegant / faster solution?