我想为指定的日期范围生成(StartDateOfMonth,EndDateOfMonth)值的列表。e、 十、时间范围:2011-09-11,2013-04-24,清单应为:
[('2011-9-11', '2011-9-30'), ('2011-10-01', '2011-10-31'), ('2011-11-01', '2011-11-30'), ('2011-12-01', '2011-12-31'), ('2012-1-01', '2012-1-31'), ('2012-2-01', '2012-2-29'), ('2012-3-01', '2012-3-31'), ('2012-4-01', '2012-4-30'), ('2012-5-01', '2012-5-31'), ('2012-6-01', '2012-6-30'), ('2012-7-01', '2012-7-31'), ('2012-8-01', '2012-8-31'), ('2012-9-01', '2012-9-30'), ('2012-10-01', '2012-10-31'), ('2012-11-01', '2012-11-30'), ('2012-12-01', '2012-12-31'), ('2013-1-01', '2013-1-31'), ('2013-2-01', '2013-2-28'), ('2013-3-01', '2013-3-31'), ('2013-4-01', '2013-4-24')]
我想出了一个有点难看的代码。这在一定程度上是因为我缺乏列表兼容性和Python的其他功能。代码是:
^{pr2}$如果这段代码可以被压缩/改进,是否需要其他开发人员的反馈?在
收益率
^{pr2}$下面是一种只使用datetime module的方法:
相关问题 更多 >
编程相关推荐