From 0d991c54b90f0b0cc32cc635ccd4833f502e9064 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Tue, 16 Jan 2024 17:19:45 +0000 Subject: [PATCH] refactor format_and_print() --- .gitignore | 2 ++ chapter11/camping.py | 3 +-- chapter11/knapsack.py | 3 +-- chapter11/travel.py | 3 +-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 68bc17f..8de3757 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,5 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ + +words_alpha.txt \ No newline at end of file diff --git a/chapter11/camping.py b/chapter11/camping.py index 24ae52f..1126a07 100644 --- a/chapter11/camping.py +++ b/chapter11/camping.py @@ -44,8 +44,7 @@ def format_and_print(table): if i == 0: continue row[0] = items[i - 1].name - table[0] = [i for i in range(W + 1)] - table[0][0] = None + table[0] = [None, *[i for i in range(1, W + 1)]] # print tabularised 2D array logger.info([item.name for item in items]) diff --git a/chapter11/knapsack.py b/chapter11/knapsack.py index 8e7b357..962f100 100644 --- a/chapter11/knapsack.py +++ b/chapter11/knapsack.py @@ -44,8 +44,7 @@ def format_and_print(table): if i == 0: continue row[0] = items[i - 1].name - table[0] = [i for i in range(W + 1)] - table[0][0] = None + table[0] = [None, *[i for i in range(1, W + 1)]] # print tabularised 2D array logger.info([item.name for item in items]) diff --git a/chapter11/travel.py b/chapter11/travel.py index f71f6e5..2cbd405 100644 --- a/chapter11/travel.py +++ b/chapter11/travel.py @@ -44,8 +44,7 @@ def format_and_print(table): if i == 0: continue row[0] = locations[i - 1].name - table[0] = [i / 2 for i in range(2 * (W + 1) - 1)] - table[0][0] = None + table[0] = [None, *[i / 2 for i in range(1, 2 * (W + 1) - 1)]] # print tabularised 2D array logger.info([item.name for item in locations])