使用
calendar模块创建一个反向字典(与任何模块一样,您将需要导入):
{month: index for index, month in enumerate(calendar.month_abbr) if month}在2.7之前的Python版本中,由于该语言不支持dict理解语法,因此您必须
dict((month, index) for index, month in enumerate(calendar.month_abbr) if month)

使用
calendar模块创建一个反向字典(与任何模块一样,您将需要导入):
{month: index for index, month in enumerate(calendar.month_abbr) if month}在2.7之前的Python版本中,由于该语言不支持dict理解语法,因此您必须
dict((month, index) for index, month in enumerate(calendar.month_abbr) if month)