Created
May 31, 2018 03:20
-
-
Save carlynorama/4e62d369bc05fa57d448886fa51cf4dd to your computer and use it in GitHub Desktop.
Get the last Tuesday of the month
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://rosettacode.org/wiki/Find_the_last_Sunday_of_each_month#Python | |
import sys | |
import calendar | |
year = 2018 | |
if len(sys.argv) > 1: | |
try: | |
year = int(sys.argv[-1]) | |
except ValueError: | |
pass | |
for month in range(1, 13): | |
last_tuesday = max(week[-6] for week in calendar.monthcalendar(year, month)) | |
print('{}-{}-{:2}'.format(year, calendar.month_abbr[month], last_tuesday)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment