【发布时间】:2018-03-05 10:08:48
【问题描述】:
测试代码:
import calendar
from collections import Counter
dates = (
'2017-05-01 11:45:35',
'2017-06-01 11:45:35',
'2017-06-01 11:45:35',
'2017-07-01 11:45:35',
)
city_file = [{'Start Time': d} for d in dates]
c = Counter((calendar.month_name[int(month['Start Time'][5:7])] for month in city_file))
print(c)
谁能解释一下代码
c = Counter((calendar.month_name[int(month['Start Time'][5:7])] for month in city_file))
尤其是部分,如果我输入 5:7 以外的任何内容,它会给出错误消息。
month['Start Time][5:7]
想要的输出:
月数示例 1 月 12 日 2 月 13 日
【问题讨论】:
-
期望的输出:月数示例 January 12 feb 13
标签: python datetime counter monthcalendar