I am trying to create a function that can convert a month number to an abbreviated month name or an abbreviated month name to a month number. I thought this might be a common question but I could not find it online.
I was thinking about the calendar module. I see that to convert from month number to abbreviated month name you can just do
calendar.month_abbr[num]
Creating a reverse dictionary would be a reasonable way to do this, because it's pretty simple:
dict((v,k) for k,v in enumerate(calendar.month_abbr))
or in recent versions of Python (2.7+) which support dictionary comprehension:
{v: k for k,v in enumerate(calendar.month_abbr)}