Created
February 18, 2017 14:07
-
-
Save guanidene/3905cd63fafd342b576e3ec7050b3d10 to your computer and use it in GitHub Desktop.
IPython Notebook File for generating list of all Saturdays and Sundays for any given year
This file contains hidden or 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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 39, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"07-01-17\n", | |
"08-01-17\n", | |
"14-01-17\n", | |
"15-01-17\n", | |
"21-01-17\n", | |
"22-01-17\n", | |
"28-01-17\n", | |
"29-01-17\n", | |
"04-02-17\n", | |
"05-02-17\n", | |
"11-02-17\n", | |
"12-02-17\n", | |
"18-02-17\n", | |
"19-02-17\n", | |
"25-02-17\n", | |
"26-02-17\n", | |
"04-03-17\n", | |
"05-03-17\n", | |
"11-03-17\n", | |
"12-03-17\n", | |
"18-03-17\n", | |
"19-03-17\n", | |
"25-03-17\n", | |
"26-03-17\n", | |
"01-04-17\n", | |
"02-04-17\n", | |
"08-04-17\n", | |
"09-04-17\n", | |
"15-04-17\n", | |
"16-04-17\n", | |
"22-04-17\n", | |
"23-04-17\n", | |
"29-04-17\n", | |
"30-04-17\n", | |
"06-05-17\n", | |
"07-05-17\n", | |
"13-05-17\n", | |
"14-05-17\n", | |
"20-05-17\n", | |
"21-05-17\n", | |
"27-05-17\n", | |
"28-05-17\n", | |
"03-06-17\n", | |
"04-06-17\n", | |
"10-06-17\n", | |
"11-06-17\n", | |
"17-06-17\n", | |
"18-06-17\n", | |
"24-06-17\n", | |
"25-06-17\n", | |
"01-07-17\n", | |
"02-07-17\n", | |
"08-07-17\n", | |
"09-07-17\n", | |
"15-07-17\n", | |
"16-07-17\n", | |
"22-07-17\n", | |
"23-07-17\n", | |
"29-07-17\n", | |
"30-07-17\n", | |
"05-08-17\n", | |
"06-08-17\n", | |
"12-08-17\n", | |
"13-08-17\n", | |
"19-08-17\n", | |
"20-08-17\n", | |
"26-08-17\n", | |
"27-08-17\n", | |
"02-09-17\n", | |
"03-09-17\n", | |
"09-09-17\n", | |
"10-09-17\n", | |
"16-09-17\n", | |
"17-09-17\n", | |
"23-09-17\n", | |
"24-09-17\n", | |
"30-09-17\n", | |
"01-10-17\n", | |
"07-10-17\n", | |
"08-10-17\n", | |
"14-10-17\n", | |
"15-10-17\n", | |
"21-10-17\n", | |
"22-10-17\n", | |
"28-10-17\n", | |
"29-10-17\n", | |
"04-11-17\n", | |
"05-11-17\n", | |
"11-11-17\n", | |
"12-11-17\n", | |
"18-11-17\n", | |
"19-11-17\n", | |
"25-11-17\n", | |
"26-11-17\n", | |
"02-12-17\n", | |
"03-12-17\n", | |
"09-12-17\n", | |
"10-12-17\n", | |
"16-12-17\n", | |
"17-12-17\n", | |
"23-12-17\n", | |
"24-12-17\n", | |
"30-12-17\n", | |
"31-12-17\n" | |
] | |
}, | |
{ | |
"ename": "StopIteration", | |
"evalue": "", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[1;31mStopIteration\u001b[0m Traceback (most recent call last)", | |
"\u001b[1;32m<ipython-input-39-ded21717ab9f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 19\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 20\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mxrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m110\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 21\u001b[1;33m \u001b[1;32mprint\u001b[0m \u001b[0mnext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msats\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 22\u001b[0m \u001b[1;32mprint\u001b[0m \u001b[0mnext\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msuns\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | |
"\u001b[1;31mStopIteration\u001b[0m: " | |
] | |
} | |
], | |
"source": [ | |
"from datetime import date, timedelta\n", | |
"\n", | |
"def allsundays(year):\n", | |
" d = date(year, 1, 5) # January 1st\n", | |
" d += timedelta(days = 6 - d.weekday()) # First Sunday\n", | |
" while d.year == year:\n", | |
" yield d.strftime(\"%d-%m-%y\")\n", | |
" d += timedelta(days = 7)\n", | |
"\n", | |
"def allsaturdays(year):\n", | |
" d = date(year, 1, 5) # January 1st\n", | |
" d += timedelta(days = 5 - d.weekday()) # First Sunday\n", | |
" while d.year == year:\n", | |
" yield d.strftime(\"%d-%m-%y\")\n", | |
" d += timedelta(days = 7)\n", | |
"\n", | |
"sats = allsaturdays(2017)\n", | |
"suns = allsundays(2017)\n", | |
"\n", | |
"for i in xrange(110):\n", | |
" print next(sats)\n", | |
" print next(suns)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment