month name to month number and vice versa in python

后端 未结 12 1184
情书的邮戳
情书的邮戳 2020-11-29 20:13

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 commo

12条回答
  •  既然无缘
    2020-11-29 20:54

    Here's yet another way to do it.

    monthToNum(shortMonth):
    
        return {
                'jan' : 1,
                'feb' : 2,
                'mar' : 3,
                'apr' : 4,
                'may' : 5,
                'jun' : 6,
                'jul' : 7,
                'aug' : 8,
                'sep' : 9, 
                'oct' : 10,
                'nov' : 11,
                'dec' : 12
        }[shortMonth]
    

提交回复
热议问题