From 8a9e80d9a2d823c90ccbbdbca268e6c65a8ac31b Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Sun, 24 Oct 2021 16:14:54 +0800 Subject: Database.group_by_status lists all statuses If there are no umbrellas that are overdue in the database, the behavior was to omit them from the returned dict. Now their values are []. Also, small comment fix. --- jimbrella/database.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/jimbrella/database.py b/jimbrella/database.py index f0d519e..f069229 100644 --- a/jimbrella/database.py +++ b/jimbrella/database.py @@ -23,7 +23,7 @@ class Database: - serial | (id) unique identifier for the umbrella. - alias | (string) future compatibility. a human readable (preferably cute) name | for a particular umbrella - - status | (string) one of ("available", "lent", "withheld", "maintenance", + - status | (string) one of ("available", "lent", "overdue", "maintenance", | "withheld", "unknown") | available : is in service on the stand | lent : is in temporary possession of a user @@ -181,7 +181,10 @@ class Database: def group_by_status(umbrellas) -> dict: """(static method) Returns umbrellas grouped into a dict by their status.""" keys = set([umb["status"] for umb in umbrellas]) - statuses = {} + # initiate statuses: each status is [] + statuses = dict.fromkeys( + ["available", "lent", "overdue", "withheld", "maintenance", "unknown"], [] + ) for key in keys: statuses[key] = [umb for umb in umbrellas if umb["status"] == key] return statuses -- cgit v1.2.3