I have a little one-liner in my Rails app that returns a range of copyright dates with an optional parameter, e.g.:
def copyright_dates(start_year = Date.today().year)
[start_year, Date.today().year].sort.uniq.join(" - ")
end
I'm moving the app over to Django, and while I love it, I miss a bit of the conciseness. The same method in Python looks like:
def copyright_dates(start_year = datetime.datetime.today().year):
years = list(set([start_year, datetime.datetime.today().year]))
years.sort()
return " - ".join(map(str, years))
It's been years since I've touched Python, so I'm betting there's an easier way to do it. Any ideas?
EDIT: I know lists and sets are a bit of overkill, but I want the following output assuming the code is run in 2009:
copyright_dates() # '2009'
copyright_dates(2007) # '2007 - 2009'
copyright_dates(2012) # '2009 - 2012'