Skip to content

Instantly share code, notes, and snippets.

@mindcube
Created March 29, 2014 05:46
Show Gist options
  • Save mindcube/9849213 to your computer and use it in GitHub Desktop.
Save mindcube/9849213 to your computer and use it in GitHub Desktop.
Generate a tuple of years in descending order in Python
from datetime import date, strftime
def _list_years(self):
x = 1
years = ()
today = date.today()
for x in range(15):
year = today - timedelta(days=365 * x)
years += (year.strftime('%Y'),)
x += 1
return years
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment