From c6a72d32e4f737be98af932fc755ef576d516362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20M=C3=BCller?= Date: Fri, 15 Oct 2021 15:36:52 +0200 Subject: [PATCH] Adding utility functions for alphabet handling --- utils/AlphabetUtils.py | 21 +++++++++++++++++++++ utils/__init__.py | 0 2 files changed, 21 insertions(+) create mode 100644 utils/AlphabetUtils.py create mode 100644 utils/__init__.py diff --git a/utils/AlphabetUtils.py b/utils/AlphabetUtils.py new file mode 100644 index 0000000..bc2d099 --- /dev/null +++ b/utils/AlphabetUtils.py @@ -0,0 +1,21 @@ +LETTERS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', + 'W', 'X', 'Y', 'Z'] + + +def get_letter_at_index(idx: int, capital: bool = False): + if idx < 0 or idx > 25: + raise AttributeError + + return LETTERS[idx] if capital else LETTERS[idx].lower() + +def get_index_of_letter(letter: str): + if letter.upper() not in LETTERS: + raise AttributeError + + return LETTERS.index(letter.upper()) + + +if __name__ == '__main__': + print(get_letter_at_index(25, True)) + print(get_index_of_letter('รค')) + diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 0000000..e69de29