I'm having a hard time keeping a dictionary in its original unsorted order. Here's my code:
monthCountDict = {'Jan': 0, 'Feb': 0, 'Mar': 0, 'Apr': 0, 'May': 0,
'Jun': 0, 'Jul': 0, 'Aug': 0, 'Sept': 0, 'Oct': 0, 'Nov': 0, 'Dec': 0}
def monthCalculator(monthNumber):
numberToMonthList = ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May',
'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec']
monthName = numberToMonthList[monthNumber]
monthCountDict[monthName] += 1
return monthCountDict
The above method of my code receives monthNumber(1,2,3 and so on) and finds its relevant monthName from numberToMonthList. This monthName's value in the dictionary monthCountDict is incremented with 1. And so on many times values are incremented for different months and every time dictionary is returned.
When I try printing the final dictionary returned, it seems to be sorted in the order of insertion. And the order of months gets jumbled!!
How do I get away with this?