I got a very simple thing to to in python: I need a list of tuples (year,month) for the last x months starting (and including) from today. So, for x=10 and toda
(year,month)
I don't see it documented anywhere, but time.mktime will "roll over" into the correct year when given out-of-range, including negative, month values:
time.mktime
x = 10 now = time.localtime() print([time.localtime(time.mktime((now.tm_year, now.tm_mon - n, 1, 0, 0, 0, 0, 0, 0)))[:2] for n in range(x)])