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/309679.html below:

Creating a list of Mondays for a year

Creating a list of Mondays for a year Creating a list of Mondays for a yearskip at pobox.com skip at pobox.com
Sun Sep 18 16:24:56 EDT 2005
    Chris> Is there a way to make python create a list of Mondays for a
    Chris> given year?  For example,

    Chris> mondays = ['1/3/2005','1/10/2005','1/17/2005','1/24/2005',
    Chris> '1/31/2005','2/7/2005',   ... ]

How about:

    import datetime

    oneday = datetime.timedelta(days=1)
    oneweek = datetime.timedelta(days=7)

    year = 2005

    start = datetime.date(year=year, month=1, day=1)
    while start.weekday() != 0:
        start += oneday

    days = []
    while start.year == year:
        days.append(start)
        start += oneweek

    print days

Skip

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