From 56dfd08cd68c14edb5fad11672c1627945c227ca Mon Sep 17 00:00:00 2001 From: Julio Morero Date: Mon, 7 Aug 2023 14:14:09 -0300 Subject: [PATCH 01/10] Fix 5_1 and 5_3 --- Exercises/ex5_1.md | 2 +- Exercises/soln5_3.md | 3 +-- Solutions/5_3/reader.py | 9 ++++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Exercises/ex5_1.md b/Exercises/ex5_1.md index e9707ba..cb08deb 100644 --- a/Exercises/ex5_1.md +++ b/Exercises/ex5_1.md @@ -115,7 +115,7 @@ kinds of input sources. For example: ```python >>> import gzip >>> import stock ->>> file = gzip.open('Data/portfolio.csv.gz') +>>> file = gzip.open('Data/portfolio.csv.gz', 'rt') >>> port = reader.csv_as_instances(file, stock.Stock) >>> port [Stock('AA', 100, 32.2), Stock('IBM', 50, 91.1), Stock('CAT', 150, 83.44), diff --git a/Exercises/soln5_3.md b/Exercises/soln5_3.md index 67ada42..217b1c2 100644 --- a/Exercises/soln5_3.md +++ b/Exercises/soln5_3.md @@ -48,11 +48,10 @@ def read_csv_as_instances(filename, cls, *, headers=None): import csv def convert_csv(lines, converter, *, headers=None): - records = [] rows = csv.reader(lines) if headers is None: headers = next(rows) - return map(lambda row: converter(headers, row), rows) + return list(map(lambda row: converter(headers, row), rows)) ``` diff --git a/Solutions/5_3/reader.py b/Solutions/5_3/reader.py index 1e68373..3926e7a 100644 --- a/Solutions/5_3/reader.py +++ b/Solutions/5_3/reader.py @@ -9,12 +9,15 @@ def convert_csv(lines, converter, *, headers=None): return list(map(lambda row: converter(headers, row), rows)) def csv_as_dicts(lines, types, *, headers=None): - return convert_csv(lines, - lambda headers, row: { name: func(val) for name, func, val in zip(headers, types, row) }) + return convert_csv(lines, + lambda headers, row: {name: func(val) for name, func, val in zip(headers, types, row)}, + headers=headers) + def csv_as_instances(lines, cls, *, headers=None): return convert_csv(lines, - lambda headers, row: cls.from_row(row)) + lambda headers, row: cls.from_row(row), + headers=headers) def read_csv_as_dicts(filename, types, *, headers=None): ''' From e414b66f4fa7c0376bf004d266595567f6c4d43a Mon Sep 17 00:00:00 2001 From: Darshan Zend Date: Fri, 18 Aug 2023 18:29:56 +0100 Subject: [PATCH 02/10] Fix broken link I think it's meant to be 6_5, unless there's a 6_6 that is missing altogether. --- Exercises/ex7_1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Exercises/ex7_1.md b/Exercises/ex7_1.md index bd2761b..c316e8c 100644 --- a/Exercises/ex7_1.md +++ b/Exercises/ex7_1.md @@ -62,7 +62,7 @@ Calling sub ## (b) A Real Decorator -In [Exercise 6.6](ex6_6.md), you created a callable class `ValidatedFunction` that +In [Exercise 6.5](ex6_5.md), you created a callable class `ValidatedFunction` that enforced type annotations. Rewrite this class as a decorator function called `validated`. It should allow you to write code like this: From a6dd2238a27f102a6135e46c3a031b47cb994712 Mon Sep 17 00:00:00 2001 From: Peili Liang Date: Fri, 8 Sep 2023 09:24:52 +0800 Subject: [PATCH 03/10] keep it consistent with solution in 1_4 --- Solutions/1_6/pcost.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Solutions/1_6/pcost.py b/Solutions/1_6/pcost.py index be53673..56518b8 100644 --- a/Solutions/1_6/pcost.py +++ b/Solutions/1_6/pcost.py @@ -12,7 +12,7 @@ def portfolio_cost(filename): # This catches errors in int() and float() conversions above except ValueError as e: - print("Couldn't parse:", line) + print("Couldn't parse:", repr(line)) print("Reason:", e) return total_cost From 374965dbfb91976467872b486f86e465296eda2d Mon Sep 17 00:00:00 2001 From: Peili Liang Date: Mon, 11 Sep 2023 10:17:26 +0800 Subject: [PATCH 04/10] fix typo in ex2_2.md --- Exercises/ex2_2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Exercises/ex2_2.md b/Exercises/ex2_2.md index 86e54ba..1248b0a 100644 --- a/Exercises/ex2_2.md +++ b/Exercises/ex2_2.md @@ -152,7 +152,7 @@ The key feature that makes this work is that a defaultdict automatically initializes elements for you--allowing an insertion of a new element and an `append()` operation to be combined together. -## (c) Data Analysis Challenge +## (d) Data Analysis Challenge In the last exercise you just wrote some code to read CSV-data related to the Chicago Transit Authority. For example, you can grab the data From 73023e88a15a6265d7bb90bdff0961cee5f4445e Mon Sep 17 00:00:00 2001 From: Poor4ever <0xpoor4ever@proton.me> Date: Thu, 28 Sep 2023 18:43:10 +0800 Subject: [PATCH 05/10] Fix duplicate input in ex2_5.md --- Exercises/ex2_5.md | 1 - 1 file changed, 1 deletion(-) diff --git a/Exercises/ex2_5.md b/Exercises/ex2_5.md index ae8072d..7950e07 100644 --- a/Exercises/ex2_5.md +++ b/Exercises/ex2_5.md @@ -60,7 +60,6 @@ and adding a few more values to it: ```python >>> row = { 'route': '22', 'date': '01/01/2001', 'daytype': 'U', 'rides': 7354 } >>> sys.getsizeof(row) ->>> sys.getsizeof(row) 240 >>> row['a'] = 1 >>> sys.getsizeof(row) From 1d20aaeca89b010b5cd74ee43e09752f2e594d69 Mon Sep 17 00:00:00 2001 From: Jarle Thorsen Date: Mon, 23 Oct 2023 12:27:05 +0200 Subject: [PATCH 06/10] Update ex5_6.md to fix NameError in example code Calling Stock() directly without providing the name of the module will result in the following error: NameError: name 'Stock' is not defined This fixes the bug in the example code. --- Exercises/ex5_6.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Exercises/ex5_6.md b/Exercises/ex5_6.md index 8afe156..4f8c950 100644 --- a/Exercises/ex5_6.md +++ b/Exercises/ex5_6.md @@ -25,7 +25,7 @@ import stock class TestStock(unittest.TestCase): def test_create(self): - s = Stock('GOOG', 100, 490.1) + s = stock.Stock('GOOG', 100, 490.1) self.assertEqual(s.name, 'GOOG') self.assertEqual(s.shares, 100) self.assertEqual(s.price, 490.1) From 81110134430d6abb2137abdac7d6e41ce9d48777 Mon Sep 17 00:00:00 2001 From: MateuszMazurek Date: Sun, 29 Oct 2023 12:09:09 +0100 Subject: [PATCH 07/10] Update formatter.py --- Solutions/9_4/structly/tableformat/formatter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Solutions/9_4/structly/tableformat/formatter.py b/Solutions/9_4/structly/tableformat/formatter.py index 893d7ba..2ce837e 100644 --- a/Solutions/9_4/structly/tableformat/formatter.py +++ b/Solutions/9_4/structly/tableformat/formatter.py @@ -1,4 +1,4 @@ -# tableformat.py +# formatter.py from abc import ABC, abstractmethod def print_table(records, fields, formatter): From 92d7dc0f9399ff2923739f225b1f46c1e1e92f18 Mon Sep 17 00:00:00 2001 From: Jarle Thorsen Date: Mon, 30 Oct 2023 14:30:21 +0100 Subject: [PATCH 08/10] Update ex6_2.md to fix variable mismatch The sell() method takes the nshares argument, however inside the method the variable shares is used instead. This patch changes the name of the argument according to the variable used within the method. --- Exercises/ex6_2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Exercises/ex6_2.md b/Exercises/ex6_2.md index a760bf5..cd90e83 100644 --- a/Exercises/ex6_2.md +++ b/Exercises/ex6_2.md @@ -160,7 +160,7 @@ class Stock(Structure): def cost(self): return self.shares * self.price - def sell(self, nshares): + def sell(self, shares): self.shares -= shares ``` From 0eedffd4292cd4adaefe0a33a0d5af96318337dd Mon Sep 17 00:00:00 2001 From: Seb Date: Sun, 19 Nov 2023 12:40:15 +0100 Subject: [PATCH 09/10] typo in ex2_2 --- Exercises/ex2_2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Exercises/ex2_2.md b/Exercises/ex2_2.md index 86e54ba..11589e6 100644 --- a/Exercises/ex2_2.md +++ b/Exercises/ex2_2.md @@ -167,7 +167,7 @@ as dictionaries like this: It would be a shame to do all of that work and then do nothing with the data. -In this exercise, you task is this: write a program to answer the +In this exercise, your task is this: write a program to answer the following three questions: 1. How many bus routes exist in Chicago? From 271ed03ff2863a536b3be7711451a85d97c33427 Mon Sep 17 00:00:00 2001 From: Seb Date: Fri, 16 Feb 2024 23:35:02 +0100 Subject: [PATCH 10/10] typo in ex2_5 --- Exercises/ex2_5.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Exercises/ex2_5.md b/Exercises/ex2_5.md index ae8072d..22b08d2 100644 --- a/Exercises/ex2_5.md +++ b/Exercises/ex2_5.md @@ -206,7 +206,7 @@ into 4 separate `append()` operations. class RideData(collections.abc.Sequence): def __init__(self): - # Each value is a list with all of the values (a column) + # Each value is a list with all the values (a column) self.routes = [] self.dates = [] self.daytypes = []