commit 953f6d7db93d3a0b80aee66b6379e8f0555f9abb
parent 6337fdd331240345a0870418a0b4465bdb88c070
Author: Chris Bracken <chris@bracken.jp>
Date: Mon, 9 Mar 2020 22:14:52 -0700
Ensure deterministic English, Japanese terms
Previously, we took the last three terms of `list(set(japanese))` which
is non-deterministic. We now take the last three terms of the sorted set
of the Japanese vocabulary words to ensure a deterministic result. A
similar fix applies to the English terms.
This change allows us to repeatedly call `kotd` as frequently as desired
with no change to the output other than once per `word_time`.
Diffstat:
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/.local/lib/python3/kotd/__init__.py b/.local/lib/python3/kotd/__init__.py
@@ -103,8 +103,8 @@ def get_words():
english = map(jengfn, w['senses'])
pos = list(filter(lambda p: p and p != "Wikipedia definition", chain(*map(jposfn, w['senses']))))[:2]
pos = sorted(set(map(transform, pos)))
- japanese = sorted(list(set(japanese))[:3])
- english = sorted(list(set(e.lower() for e in chain(*english)))[:3])
+ japanese = sorted(list(set(japanese)))[:3]
+ english = sorted(list(set(e.lower() for e in chain(*english))))[:3]
words.append(f"{c}: {', '.join(japanese)} [{', '.join(pos)}]: {', '.join(english)}")
# </div>