>>> import calendar >>> [y[4] for y in calendar.monthcalendar(2005, 9) if y[4]!=0][2] 16 >>> [y[4] for y in calendar.monthcalendar(2003, 6) if y[4]!=0][2] 20 >>> [y[4] for y in calendar.monthcalendar(2006, 2) if y[4]!=0][2] 17