From 84e53b203174d0a8c830898d0b0fdc2c95f4dc16 Mon Sep 17 00:00:00 2001 From: Rick van Hattem Date: Sat, 25 Jan 2020 12:43:11 +0100 Subject: [PATCH 1/4] update formatting for Github --- 03_containers_and_collections/03_dict.rst | 86 ++++++++++++----------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/03_containers_and_collections/03_dict.rst b/03_containers_and_collections/03_dict.rst index 3dbeab4..57329a2 100644 --- a/03_containers_and_collections/03_dict.rst +++ b/03_containers_and_collections/03_dict.rst @@ -1,44 +1,48 @@ ->>> def most_significant(value): -... while value >= 10: -... value //= 10 -... return value - ->>> most_significant(12345) -1 ->>> most_significant(99) -9 ->>> most_significant(0) -0 +.. highlight:: python + + >>> def most_significant(value): + ... while value >= 10: + ... value //= 10 + ... return value + + >>> most_significant(12345) + 1 + >>> most_significant(99) + 9 + >>> most_significant(0) + 0 ------------------------------------------------------------------------------ ->>> def add(collection, key, value): -... index = most_significant(key) -... collection[index].append((key, value)) - ->>> def contains(collection, key): -... index = most_significant(key) -... for k, v in collection[index]: -... if k == key: -... return True -... return False - -# Create the collection of 10 lists ->>> collection = [[], [], [], [], [], [], [], [], [], []] - -# Add some items, using key/value pairs ->>> add(collection, 123, 'a') ->>> add(collection, 456, 'b') ->>> add(collection, 789, 'c') ->>> add(collection, 101, 'c') - -# Look at the collection ->>> collection -[[], [(123, 'a'), (101, 'c')], [], [], - [(456, 'b')], [], [], [(789, 'c')], [], []] - -# Check if the contains works correctly ->>> contains(collection, 123) -True ->>> contains(collection, 1) -False +.. highlight:: + + >>> def add(collection, key, value): + ... index = most_significant(key) + ... collection[index].append((key, value)) + + >>> def contains(collection, key): + ... index = most_significant(key) + ... for k, v in collection[index]: + ... if k == key: + ... return True + ... return False + + Create the collection of 10 lists + >>> collection = [[], [], [], [], [], [], [], [], [], []] + + Add some items, using key/value pairs + >>> add(collection, 123, 'a') + >>> add(collection, 456, 'b') + >>> add(collection, 789, 'c') + >>> add(collection, 101, 'c') + + Look at the collection + >>> collection + [[], [(123, 'a'), (101, 'c')], [], [], + [(456, 'b')], [], [], [(789, 'c')], [], []] + + Check if the contains works correctly + >>> contains(collection, 123) + True + >>> contains(collection, 1) + False From ab5f676f6954a7104f7c2aa8178242835ddb7bf0 Mon Sep 17 00:00:00 2001 From: Rick van Hattem Date: Sat, 25 Jan 2020 12:45:23 +0100 Subject: [PATCH 2/4] Fixed Github compatibility --- 03_containers_and_collections/03_dict.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/03_containers_and_collections/03_dict.rst b/03_containers_and_collections/03_dict.rst index 57329a2..c9091c8 100644 --- a/03_containers_and_collections/03_dict.rst +++ b/03_containers_and_collections/03_dict.rst @@ -1,4 +1,4 @@ -.. highlight:: python +.. code-block:: python >>> def most_significant(value): ... while value >= 10: @@ -14,7 +14,7 @@ ------------------------------------------------------------------------------ -.. highlight:: +.. code-block:: python >>> def add(collection, key, value): ... index = most_significant(key) From 50b4d00416c0ee3c15ac83f9a4fb545d909dcf69 Mon Sep 17 00:00:00 2001 From: Khushl Vora <67469072+K-Titan@users.noreply.github.com> Date: Thu, 1 Oct 2020 17:58:08 +0530 Subject: [PATCH 3/4] Update README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index c13c265..15d3145 100644 --- a/README.rst +++ b/README.rst @@ -5,7 +5,7 @@ Code samples from Mastering Python (https://www.packtpub.com/application-development/mastering-python) All of the code in this repository is tested using the bundled tests. To run -the tests yourself simply install the requirements and run the tests: +the tests yourself you just have to install the requirements and run the tests: pip3 install --upgrade --requirement requirements.txt py.test From 2405e38c8d8d91884977146471b571e14953264a Mon Sep 17 00:00:00 2001 From: Rick van Hattem Date: Tue, 1 Nov 2022 20:33:34 +0100 Subject: [PATCH 4/4] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a127a51 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Rick van Hattem + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.