A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/329897.html below:

Creating a list of Mondays for a year

Creating a list of Mondays for a yearPaul Rubin http
Sun Sep 18 20:32:30 EDT 2005
Chris <secun at yahoo.com> 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4