Adding utility functions for alphabet handling

This commit is contained in:
Patrick Müller 2021-10-15 15:36:52 +02:00
parent 8c63cedfa4
commit c6a72d32e4
2 changed files with 21 additions and 0 deletions

21
utils/AlphabetUtils.py Normal file
View File

@ -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('ä'))

0
utils/__init__.py Normal file
View File