我有以下单元格数组:
from datetime import datetime
from datetime import timedelta
def next_month_generator(d):
while True:
if d.month == 12:
# on Dec, need to change year
d = d.replace(year=d.year+1, month=1)
else:
try:
# get next month, same date
d = d.replace(month=d.month+1)
except ValueError:
# get next month, last months date
d = date(year=d.year, month=d.month+2, day=1) - timedelta(days=1)
yield d
start_date=date(2017, 01, 31)
nm = next_month_generator(start_date)
for _ in range(13):
print(nm.next())
>> 2017-02-28
>> 2017-03-28
>> 2017-04-28
>> 2017-05-28
>> 2017-06-28
>> 2017-07-28
>> 2017-08-28
>> 2017-09-28
>> 2017-10-28
>> 2017-11-28
>> 2017-12-28
>> 2018-01-28
>> 2018-02-28
如何在特定位置插入另一个字符串?例如,我想将a = {'a', 'b', 'c', 'd'}
字符串放在第3位,以获得:
'1'
答案 0 :(得分:3)
它可以用与矩阵相同的方式完成:
a = {a{1:2}, '1', a{3:end}}