From 413db1d2b198401ec31b923a77e946e2d6799258 Mon Sep 17 00:00:00 2001 From: jmgilliss <47050911+jmgilliss@users.noreply.github.com> Date: Sat, 4 Jan 2020 21:25:08 -0600 Subject: [PATCH 1/5] Update collections.ipynb 3.6.1 to 3.7.5 --- days/04-06-collections/collections.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/days/04-06-collections/collections.ipynb b/days/04-06-collections/collections.ipynb index 2a4fc224..2814bca7 100644 --- a/days/04-06-collections/collections.ipynb +++ b/days/04-06-collections/collections.ipynb @@ -805,7 +805,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.1" + "version": "3.7.5" } }, "nbformat": 4, From 8056f69164e0b8594bc5bca5c8101932ddb8b870 Mon Sep 17 00:00:00 2001 From: jmgilliss <47050911+jmgilliss@users.noreply.github.com> Date: Sat, 11 Jan 2020 15:58:58 -0600 Subject: [PATCH 2/5] at day 10 --- days/04-06-collections/collections.ipynb | 2 +- days/10-12-pytest/guess/guess.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/days/04-06-collections/collections.ipynb b/days/04-06-collections/collections.ipynb index 2814bca7..6caee64c 100644 --- a/days/04-06-collections/collections.ipynb +++ b/days/04-06-collections/collections.ipynb @@ -805,7 +805,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.5" + "version": "3.7.6" } }, "nbformat": 4, diff --git a/days/10-12-pytest/guess/guess.py b/days/10-12-pytest/guess/guess.py index b2ed9efc..35b81268 100644 --- a/days/10-12-pytest/guess/guess.py +++ b/days/10-12-pytest/guess/guess.py @@ -28,18 +28,18 @@ def guess(self): If all good, return the int""" guess = input(f'Guess a number between {START} and {END}: ') if not guess: - raise ValueError('Please enter a number') + raise ValueError('Gimme a number:') try: guess = int(guess) except ValueError: - raise ValueError('Should be a number') + raise ValueError('Enter a fucking number') if guess not in range(START, END+1): - raise ValueError('Number not in range') + raise ValueError("What don't you understand abou 1 to 20?") if guess in self._guesses: - raise ValueError('Already guessed') + raise ValueError('Already did that dumbass!') self._guesses.add(guess) return guess From 5e4eb27da4ab9058fdcf20d82ec9c0aa692223ae Mon Sep 17 00:00:00 2001 From: jmgilliss <47050911+jmgilliss@users.noreply.github.com> Date: Sat, 11 Jan 2020 16:00:14 -0600 Subject: [PATCH 3/5] at day 09 --- days/07-09-data-structures/cars.ipynb | 157 ++++++++++++++++++ days/07-09-data-structures/code/cars.py | 47 ++++++ days/07-09-data-structures/code/cars_test.py | 51 ++++++ .../07-09-data-structures/code/state_stuff.py | 30 ++++ 4 files changed, 285 insertions(+) create mode 100644 days/07-09-data-structures/cars.ipynb create mode 100644 days/07-09-data-structures/code/cars.py create mode 100644 days/07-09-data-structures/code/cars_test.py create mode 100644 days/07-09-data-structures/code/state_stuff.py diff --git a/days/07-09-data-structures/cars.ipynb b/days/07-09-data-structures/cars.ipynb new file mode 100644 index 00000000..621dd00a --- /dev/null +++ b/days/07-09-data-structures/cars.ipynb @@ -0,0 +1,157 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "cars = {\n", + " 'Ford': ['Falcon', 'Focus', 'Festiva', 'Fairlane', 'Trail'],\n", + " 'Holden': ['Commodore', 'Captiva', 'Barina', 'Trailblazer'],\n", + " 'Nissan': ['Maxima', 'Pulsar', '350Z', 'Navara'],\n", + " 'Honda': ['Civic', 'Accord', 'Odyssey', 'Jazz'],\n", + " 'Jeep': ['Grand Cherokee', 'Cherokee', 'Trailhawk', 'Trackhawk']\n", + "}\n", + "\n", + "\n", + "def get_all_jeeps(cars=cars):\n", + " \"\"\"return a comma + space (', ') separated string of jeep models\n", + " (original order)\"\"\"\n", + " for key, value in cars.items():\n", + " if key == 'Jeep':\n", + " models = (value)\n", + " \n", + " return models\n", + " \n", + " \n", + "def get_first_model_each_manufacturer(cars=cars):\n", + " \"\"\"return a list of matching models (original ordering)\"\"\"\n", + " stuff = list()\n", + " for key, value in cars.items():\n", + " stuff.append(value[0])\n", + " return stuff\n", + "\n", + "\n", + "def get_all_matching_models(cars=cars, grep='trail'):\n", + " \"\"\"return a list of all models containing the case insensitive\n", + " 'grep' string which defaults to 'trail' for this exercise,\n", + " sort the resulting sequence alphabetically\"\"\"\n", + " matches = []\n", + " for key, value in cars.items():\n", + " for i in value:\n", + " temp = str(value[i])\n", + " temp = temp.lower()\n", + " print(temp)\n", + " if grep in temp:\n", + " matches.append(value)\n", + " return matches\n", + "\n", + "\n", + "def sort_car_models(cars=cars):\n", + " \"\"\"return a copy of the cars dict with the car models (values)\n", + " sorted alphabetically\"\"\"\n", + " pass" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Grand Cherokee', 'Cherokee', 'Trailhawk', 'Trackhawk']" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_all_jeeps()" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Falcon', 'Commodore', 'Maxima', 'Civic', 'Grand Cherokee']" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_first_model_each_manufacturer()" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "list indices must be integers or slices, not str", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mget_all_matching_models\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;32m\u001b[0m in \u001b[0;36mget_all_matching_models\u001b[1;34m(cars, grep)\u001b[0m\n\u001b[0;32m 33\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mkey\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mcars\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 34\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 35\u001b[1;33m \u001b[0mtemp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 36\u001b[0m \u001b[0mtemp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtemp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlower\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 37\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtemp\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: list indices must be integers or slices, not str" + ] + } + ], + "source": [ + "get_all_matching_models()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sort_car_models()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/days/07-09-data-structures/code/cars.py b/days/07-09-data-structures/code/cars.py new file mode 100644 index 00000000..5a7fecb8 --- /dev/null +++ b/days/07-09-data-structures/code/cars.py @@ -0,0 +1,47 @@ +cars = { + 'Ford': ['Falcon', 'Focus', 'Festiva', 'Fairlane'], + 'Holden': ['Commodore', 'Captiva', 'Barina', 'Trailblazer'], + 'Nissan': ['Maxima', 'Pulsar', '350Z', 'Navara'], + 'Honda': ['Civic', 'Accord', 'Odyssey', 'Jazz'], + 'Jeep': ['Grand Cherokee', 'Cherokee', 'Trailhawk', 'Trackhawk'] +} + + +def get_all_jeeps(cars=cars): + """return a comma + space (', ') separated string of jeep models + (original order)""" + for key, value in cars.items(): + if key =='Jeep': + value = (str(value)) + print(type(value), value) + return value + + + + +def get_first_model_each_manufacturer(cars=cars): + """return a list of matching models (original ordering)""" + stuff = list() + for key, value in cars.items(): + stuff.append(value[0]) + return stuff + + +def get_all_matching_models(cars=cars, grep='trail'): + """return a list of all models containing the case insensitive + 'grep' string which defaults to 'trail' for this exercise, + sort the resulting sequence alphabetically""" + matches = () + for key, value in cars.items(): + if grep in value: + matches.append(value) + + return matches + + +def sort_car_models(cars=cars): + """return a copy of the cars dict with the car models (values) + sorted alphabetically""" + pass + +get_all_jeeps() \ No newline at end of file diff --git a/days/07-09-data-structures/code/cars_test.py b/days/07-09-data-structures/code/cars_test.py new file mode 100644 index 00000000..d62eb43b --- /dev/null +++ b/days/07-09-data-structures/code/cars_test.py @@ -0,0 +1,51 @@ +import unittest + + +class MyTestCase(unittest.TestCase): + def test_something(self): + self.assertEqual(True, False) + +from cars import (get_all_jeeps, get_first_model_each_manufacturer, + get_all_matching_models, sort_car_models) + + +def test_get_all_jeeps(): + expected = 'Grand Cherokee, Cherokee, Trailhawk, Trackhawk' + actual = get_all_jeeps() + assert type(actual) == str + assert actual == expected + + +def test_get_first_model_each_manufacturer(): + actual = get_first_model_each_manufacturer() + expected = ['Falcon', 'Commodore', 'Maxima', 'Civic', 'Grand Cherokee'] + assert actual == expected + + +def test_get_all_matching_models_default_grep(): + expected = ['Trailblazer', 'Trailhawk'] + assert get_all_matching_models() == expected + + +def test_get_all_matching_models_different_grep(): + expected = ['Accord', 'Commodore', 'Falcon'] + assert get_all_matching_models(grep='CO') == expected + + +def test_sort_dict_alphabetically(): + actual = sort_car_models() + # Order of keys should not matter, two dicts are equal if they have the + # same keys and the same values. + # The car models (values) need to be sorted here though + expected = { + 'Ford': ['Fairlane', 'Falcon', 'Festiva', 'Focus'], + 'Holden': ['Barina', 'Captiva', 'Commodore', 'Trailblazer'], + 'Honda': ['Accord', 'Civic', 'Jazz', 'Odyssey'], + 'Jeep': ['Cherokee', 'Grand Cherokee', 'Trackhawk', 'Trailhawk'], + 'Nissan': ['350Z', 'Maxima', 'Navara', 'Pulsar'], + } + assert actual == expected + + +if __name__ == '__main__': + unittest.main() diff --git a/days/07-09-data-structures/code/state_stuff.py b/days/07-09-data-structures/code/state_stuff.py new file mode 100644 index 00000000..84233e01 --- /dev/null +++ b/days/07-09-data-structures/code/state_stuff.py @@ -0,0 +1,30 @@ +from data import us_state_abbrev as usab +from data import states_list as slist + + +def load_stuff(): + print(usab) + print(slist) + return + + +def tenth_each(): + + for key, value in enumerate(usab.items()): + if key == 10: + print(key, value) + if key == 45: + print(key) + if key == 27: + print(value[0]) + for item in enumerate(slist): + pass + return + +def main(): + #load_stuff() + tenth_each() + + +if __name__ == "__main__": + main() From 7a291e9efdb055de8c43bdc996cf2d534acb9f73 Mon Sep 17 00:00:00 2001 From: jmgilliss <47050911+jmgilliss@users.noreply.github.com> Date: Sat, 11 Jan 2020 16:50:55 -0600 Subject: [PATCH 4/5] at day 10 --- days/01-03-datetimes/bite67.ipynb | 94 +++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 days/01-03-datetimes/bite67.ipynb diff --git a/days/01-03-datetimes/bite67.ipynb b/days/01-03-datetimes/bite67.ipynb new file mode 100644 index 00000000..55f14e0f --- /dev/null +++ b/days/01-03-datetimes/bite67.ipynb @@ -0,0 +1,94 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [], + "source": [ + "from datetime import datetime, date, timedelta\n", + "import pytest\n", + "\n", + "start_100days = date(2017, 3, 30)\n", + "pybites_founded = date(2016, 12, 19)\n", + "pycon_date = date(2018, 5, 8)\n", + "\n", + "\n", + "def get_hundred_days_end_date():\n", + " end_time = start_100days + timedelta(days=100)\n", + " return str(end_time)\n", + "\n", + "\n", + " \n", + "def get_days_between_pb_start_first_joint_pycon(): \n", + " \n", + " resultstr = pycon_date - pybites_founded\n", + " result = resultstr.days\n", + " \n", + " \"\"\"Return the int number of days\"\"\"\n", + " return int(result)" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'2017-07-08'" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_hundred_days_end_date()" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "505" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_days_between_pb_start_first_joint_pycon()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 1e68e2355d6952ba0784361fcd20a5667189104f Mon Sep 17 00:00:00 2001 From: jmgilliss <47050911+jmgilliss@users.noreply.github.com> Date: Sun, 12 Jan 2020 13:06:02 -0600 Subject: [PATCH 5/5] at day 11 --- days/07-09-data-structures/code/cars.py | 53 ++++++++++++++----------- days/10-12-pytest/guess/guess.py | 2 +- days/10-12-pytest/guess/test_guess.py | 4 +- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/days/07-09-data-structures/code/cars.py b/days/07-09-data-structures/code/cars.py index 5a7fecb8..a76f6e4a 100644 --- a/days/07-09-data-structures/code/cars.py +++ b/days/07-09-data-structures/code/cars.py @@ -1,3 +1,5 @@ +from itertools import chain + cars = { 'Ford': ['Falcon', 'Focus', 'Festiva', 'Fairlane'], 'Holden': ['Commodore', 'Captiva', 'Barina', 'Trailblazer'], @@ -7,41 +9,44 @@ } -def get_all_jeeps(cars=cars): +def get_all_jeeps(): """return a comma + space (', ') separated string of jeep models (original order)""" - for key, value in cars.items(): - if key =='Jeep': - value = (str(value)) - print(type(value), value) - return value - - + print(', '.join(cars['Jeep'])) + return ', '.join(cars['Jeep']) -def get_first_model_each_manufacturer(cars=cars): +def get_first_model_each_manufacturer(): """return a list of matching models (original ordering)""" - stuff = list() - for key, value in cars.items(): - stuff.append(value[0]) - return stuff + print([models[0] for models in cars.values()]) + return [models[0] for models in cars.values()] -def get_all_matching_models(cars=cars, grep='trail'): +def get_all_matching_models(cars, grep='trail'): """return a list of all models containing the case insensitive 'grep' string which defaults to 'trail' for this exercise, sort the resulting sequence alphabetically""" - matches = () - for key, value in cars.items(): - if grep in value: - matches.append(value) + grep = grep.lower() + # flatten list of lists (less obvious way: "sum(cars.values(), [])") + models = list(chain.from_iterable(cars.values())) + matching_models = [model for model in models + if grep in model.lower()] + print(sorted(matching_models)) + return sorted(matching_models) - return matches - -def sort_car_models(cars=cars): +def sort_car_models(): """return a copy of the cars dict with the car models (values) sorted alphabetically""" - pass - -get_all_jeeps() \ No newline at end of file + print({manufacturer: sorted(models) for + manufacturer, models in cars.items()}) + return {manufacturer: sorted(models) for + manufacturer, models in cars.items()} +def main(): + get_all_jeeps() + get_first_model_each_manufacturer() + get_first_model_each_manufacturer() + sort_car_models() + +if __name__ == "__main__": + main() diff --git a/days/10-12-pytest/guess/guess.py b/days/10-12-pytest/guess/guess.py index 35b81268..deb2dd04 100644 --- a/days/10-12-pytest/guess/guess.py +++ b/days/10-12-pytest/guess/guess.py @@ -36,7 +36,7 @@ def guess(self): raise ValueError('Enter a fucking number') if guess not in range(START, END+1): - raise ValueError("What don't you understand abou 1 to 20?") + raise ValueError("What don't you understand about 1 to 20?") if guess in self._guesses: raise ValueError('Already did that dumbass!') diff --git a/days/10-12-pytest/guess/test_guess.py b/days/10-12-pytest/guess/test_guess.py index 579313fb..761ecdd9 100644 --- a/days/10-12-pytest/guess/test_guess.py +++ b/days/10-12-pytest/guess/test_guess.py @@ -65,8 +65,8 @@ def test_game_win(inp, capfd): assert game._win is True out = capfd.readouterr()[0] - expected = ['4 is too low', 'Number not in range', - '9 is too high', 'Already guessed', + expected = ['4 is too low', "What don't you understand about 1 to 20?", + '9 is too high', 'Already did that dumbass!', '6 is correct!', 'It took you 3 guesses'] output = [line.strip() for line