python assign list item in for loop

Solutions on MaxInterview for python assign list item in for loop by the best coders in the world

showing results for - "python assign list item in for loop"
Chahine
26 Jun 2016
1year = 2021
2month_list = [1, 2, 3, 4, 5]
3day = 1
4date_list = []
5
6for month in month_list:
7    date_list.append( datetime(year, month, day).strftime("%Y-%m-%d") )
8
9print(date_list)    
10# ['2021-01-01', '2021-02-01', '2021-03-01', '2021-04-01', '2021-05-01']