aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar jesopo2018-10-04 05:33:15 +0100
committerGravatar jesopo2018-10-04 05:33:15 +0100
commit75f25db4cd0b0008447083ed56f052758520af1a (patch)
tree4d4f394fe32e15bbb2b191a1095294e0bacfb111 /src
parentActually use the sorted mode list in print_activity (diff)
signature
Move 'top 10' logic to utils, add !wordiest to modules/words.py
Diffstat (limited to 'src')
-rw-r--r--src/utils/__init__.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/utils/__init__.py b/src/utils/__init__.py
index 54430256..dccc1faf 100644
--- a/src/utils/__init__.py
+++ b/src/utils/__init__.py
@@ -171,3 +171,14 @@ def parse_docstring(s):
description += " "
description += line
return Docstring(description, items)
+
+def top_10(items, convert_key=lambda x: x, value_format=lambda x: x):
+ top_10 = sorted(items.keys())
+ top_10 = sorted(top_10, key=items.get, reverse=True)[:10]
+
+ top_10_items = []
+ for key in top_10:
+ top_10_items.append("%s (%s)" % (convert_key(key),
+ value_format(items[key])))
+
+ return top_10_items