I have a list that contains strings of dates; not only months ("Jan year x", "Feb year x"), but also Quarters ("Q1 of year x", "Q2 of year x") and seasons and years. The Seasons are "Winter" (October of year x to March of year x+1) and "Summer", defined as Apr of year x to Sep of year).
I want to sort the months from Jan
to Dec
of each year, then add the quarters after the three months that define, and then the seasons after the 6 months that define them, and finally the year after the 12 months that define them.
So, lets say the year is 2000
, I would need to pass through these steps in order to get the end list:
Sort the Months of the year:
I would get:
Jan 2000, Feb 2000, Mar 2000, Apr 2000, May 2000, Jun 2000, Jul 2000, Aug 2000, Sep 2000, Oct 2000, Nov 2000, Dec 2000
Add the Quarters:
Jan 2000, Feb 2000, Mar 2000, Q1 2000,Apr 2000, May 2000, Jun 2000,Q2 2000, Jul 2000, Aug 2000, Sep 2000, Q3 2000,Oct 2000, Nov 2000, Dec 2000, Q4 2000
Add the Seasons:
Jan 2000, Feb 2000, Mar 2000, Q1 2000, Win 1999, Apr 2000, May 2000, Jun 2000,Q2 2000, Jul 2000,Aug 2000, Sep 2000, Q3 2000, Sum 2000, Oct 2000, Nov 2000, Dec 2000, Q4 2000
Last step, add the years:
Jan 2000, Feb 2000, Mar 2000, Q1 2000, Win 1999, Apr 2000, May 2000, Jun 2000, Q2 2000, Jul 2000,Aug 2000, Sep 2000, Q3 2000, Sum 2000, Oct 2000, Nov 2000, Dec 2000, Q4 2000, Year 2000
Keep in mind these are all strings and not integers. The list that I begin with is this:
temp2 = ['2015',
'2016',
'2017',
'2018',
'2019',
'2020',
'Apr-14',
'Apr-15',
'Apr-16',
'Apr-17',
'Aug-14',
'Aug-15',
'Aug-16',
'Dec-14',
'Dec-15',
'Dec-16',
'Feb-14',
'Feb-15',
'Feb-16',
'Feb-17',
'Jan-15',
'Jan-16',
'Jan-17',
'Jul-14',
'Jul-15',
'Jul-16',
'Jun-14',
'Jun-15',
'Jun-16',
'Mar-14',
'Mar-15',
'Mar-16',
'Mar-17',
'May-14',
'May-15',
'May-16',
'Nov-14',
'Nov-15',
'Nov-16',
'Oct-14',
'Oct-15',
'Oct-16',
'Q115',
'Q116',
'Q117',
'Q214',
'Q215',
'Q216',
'Q217',
'Q314',
'Q315',
'Q316',
'Q414',
'Q415',
'Q416',
'Q417',
'Sep-14',
'Sep-15',
'Sep-16',
'Sum 14',
'Sum 15',
'Sum 16',
'Sum 17',
'Sum 18',
'Win 14',
'Win 15',
'Win 16',
'Win 17',
'Win 18',
'Win 19']
What I have tried is this:
temp3 = {}
for i in range(len(temp2)):
if temp2[i][0] == '2':
temp3[temp2[i][2:]] = list()
for i in range(len(temp2)):
for key in temp3:
if temp2[i][2:] == key:
temp3[key].append(temp2[i])
then I am stumped as I don't know how to get the months of that year and not nothing.