From: Jiri Vlasak Date: Mon, 25 Mar 2019 12:38:16 +0000 (+0100) Subject: Update sort to include second field X-Git-Tag: v0.2.0~3^2~4 X-Git-Url: https://rtime.felk.cvut.cz/gitweb/hubacji1/coffee-getter.git/commitdiff_plain/089b6be7ab77171620661923d34164a26438c45f Update sort to include second field --- diff --git a/cbdb.py b/cbdb.py index 5eda3d5..3f7f056 100644 --- a/cbdb.py +++ b/cbdb.py @@ -50,5 +50,5 @@ class Db: top = [] for (un, cnt) in users.items(): top.append((un, cnt)) - top.sort(key=lambda x: x[1], reverse=True) + top.sort(key=lambda x: (x[1], x[0]), reverse=True) return top diff --git a/ut/test_db.py b/ut/test_db.py index 0aae05d..32fd3f0 100644 --- a/ut/test_db.py +++ b/ut/test_db.py @@ -142,7 +142,7 @@ class TopMateDrinkers(TestCase): db = Db(TESTDB_FILENAME) top = db.getTopMateDrinkers() topsorted = list(top) - topsorted.sort(key=lambda x: x[1], reverse=True) + topsorted.sort(key=lambda x: (x[1], x[0]), reverse=True) self.assertEqual( top, topsorted @@ -155,7 +155,7 @@ class TopMateDrinkers(TestCase): db = Db(cfg.getCoffeeDbPath()) top = db.getTopMateDrinkers() topsorted = list(top) - topsorted.sort(key=lambda x: x[1], reverse=True) + topsorted.sort(key=lambda x: (x[1], x[0]), reverse=True) self.assertEqual( top, topsorted