サイトにアクセスしたタイミングから15ヶ月のリストを作ろうとしています、
リストは各月の1日で表示します
python
1力技で近いことはできるのですが 2[f"{y}-{m:02d}-01" for m in range(1,13) for y in ["2017", "2018"]] 3['2017-01-01', 4 '2018-01-01', 5 '2017-02-01', 6 '2018-02-01', 7 '2017-03-01', 8 '2018-03-01', 9 '2017-04-01', 10 '2018-04-01', 11 '2017-05-01', 12 '2018-05-01', 13 '2017-06-01', 14 '2018-06-01', 15 '2017-07-01', 16 '2018-07-01', 17 '2017-08-01', 18 '2018-08-01', 19 '2017-09-01', 20 '2018-09-01', 21 '2017-10-01', 22 '2018-10-01', 23 '2017-11-01', 24 '2018-11-01', 25 '2017-12-01', 26 '2018-12-01']
python
1import maya 2import datetime 3 4current_month = maya.when("today") 5first_day = lambda year, month: datetime.date(year, month, 1).strftime('%Y-%m-%d') 6first_day(current_month.year, current_month.month) 7 8結果=> '2018-08-01' ここからスタートして 9 10本当に作りたいリスト 11['2017-05-01'...'2018-07-01','2018-08-01'] 12
何かいい方法はありますか?
python
1import maya 2import datetime 3 4start_day = maya.when("15 month") 5 6first_day = lambda year, month: datetime.date(year, month, 1).strftime('%Y-%m-%d') 7 8[maya.when(f"{first_day(start_day.year, start_day.month)} + {a} month").iso8601() for a in range(1, 16)] 9 10['2018-07-01', 11 '2018-06-01', 12 '2018-05-01', 13 '2018-04-01', 14 '2018-03-01', 15 '2018-02-01', 16 '2018-01-01', 17 '2017-12-01', 18 '2017-11-01', 19 '2017-10-01', 20 '2017-09-01', 21 '2017-08-01', 22 '2017-07-01', 23 '2017-06-01', 24 '2017-05-01'] 25
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。