From 4d6a267fd799a9881a889b818e14b49865ec3af8 Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Tue, 12 Dec 2023 20:49:29 +0000 Subject: [PATCH] Use neater syntax for side effect using generator --- one-time-tasks/verbal_noun_rename.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/one-time-tasks/verbal_noun_rename.py b/one-time-tasks/verbal_noun_rename.py index 4bd4a5e..9fd6408 100644 --- a/one-time-tasks/verbal_noun_rename.py +++ b/one-time-tasks/verbal_noun_rename.py @@ -10,6 +10,10 @@ with open("verbal_nouns.json") as f: GRAVE = chr(0x300) ACUTE = chr(0x301) +# Consume an iterator. For doing side effects using a generator expression in one line. +def do(iter): + for _ in iter: pass + def get_verbal_nouns(verb: str) -> str: return VERBAL_NOUNS[verb] @@ -31,8 +35,8 @@ def fix_infl_template(template: mwparserfromhell.nodes.Template): if "vnoun" in template.params or "verbal noun" in template.params: if is_indef and is_singular: - [remove_positional_by_value(i) for i in indef] - [remove_positional_by_value(s) for s in singular] + do(remove_positional_by_value(i) for i in indef) + do(remove_positional_by_value(s) for s in singular) else: verb = str(template.get(2)).replace(GRAVE, "").replace(ACUTE, "") try: