From 8be22bd4a441eae328fd7b11f9123a5ac2261d75 Mon Sep 17 00:00:00 2001 From: Tony Lam Date: Wed, 21 Aug 2024 23:40:01 +0300 Subject: [PATCH] feat: Sort restaurant sausage availability by date The code changes in this commit modify the `unicafe_global_sausagesearch` function in `app.py` to sort the restaurant sausage availability by date. The function now creates a list of restaurants and dates as tuples, sorts them by date, and returns the sorted dictionary of restaurants and dates. --- app.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index cadd153..eba8c51 100644 --- a/app.py +++ b/app.py @@ -120,7 +120,18 @@ def unicafe_global_sausagesearch(): if sausage_dates: restaurant_sausage_dict[restaurant] = sausage_dates - return restaurant_sausage_dict + # make a list of restaurants and dates as tuples + sortedRestaurantsDate = list(restaurant_sausage_dict.items()) + + # func to return the pure date of sausage availability of a restaurant + def returndate(item): + return item[1][0][3:8] + + # sort the items by date + sortedRestaurantsDate.sort(key=returndate) + sortedRestaurantsDate = dict(sortedRestaurantsDate) + + return sortedRestaurantsDate @app.route("/")