2021-10-15 13:36:52 +00:00
|
|
|
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']
|
|
|
|
|
|
|
|
|
2021-10-15 16:22:31 +00:00
|
|
|
def is_letter_of_alphabet(letter: str):
|
|
|
|
"""
|
|
|
|
Checks if the given letter is a valid letter of the alphabet
|
|
|
|
:param letter: The letter to check
|
|
|
|
:return: If the letter is in the alphabet
|
|
|
|
"""
|
|
|
|
return letter.upper() in LETTERS
|
|
|
|
|
|
|
|
|
2021-10-15 13:36:52 +00:00
|
|
|
def get_letter_at_index(idx: int, capital: bool = False):
|
2021-10-15 16:22:31 +00:00
|
|
|
"""
|
|
|
|
Returns the letter at the given index
|
|
|
|
:param idx: The index of the letter to return
|
|
|
|
:param capital: If the capitalized letter should be returned
|
|
|
|
:return: The letter
|
|
|
|
"""
|
2021-10-15 13:36:52 +00:00
|
|
|
if idx < 0 or idx > 25:
|
|
|
|
raise AttributeError
|
|
|
|
|
|
|
|
return LETTERS[idx] if capital else LETTERS[idx].lower()
|
|
|
|
|
2021-10-15 14:10:44 +00:00
|
|
|
|
2021-10-15 13:36:52 +00:00
|
|
|
def get_index_of_letter(letter: str):
|
2021-10-15 16:22:31 +00:00
|
|
|
"""
|
|
|
|
Returns the index of the given letter
|
|
|
|
:param letter: The letter to return the index of
|
|
|
|
:return: The index of the letter
|
|
|
|
"""
|
2021-10-15 13:36:52 +00:00
|
|
|
if letter.upper() not in LETTERS:
|
|
|
|
raise AttributeError
|
|
|
|
|
|
|
|
return LETTERS.index(letter.upper())
|