Creating a list of Mondays for a year

Paul Rubin http
Mon Sep 19 02:32:30 CEST 2005

Chris <secun at> writes:
> Is there a way to make python create a list of Mondays for a given year?
> mondays = ['1/3/2005','1/10/2005','1/17/2005','1/24/2005',
> '1/31/2005','2/7/2005',   ... ]

This is pretty inefficient but it's conceptually the simplest:

def mondays(year):
    from calendar import weekday, monthrange
    return [('%d/%d/%d'%(month,day,year))
             for month in xrange(1,13)
               for day in xrange(1,1+monthrange(year,month)[1])
                 if weekday(year,month,day) == 0]

More information about the Python-list mailing list