With so many unusual and contradictory grammar rules, the English language has many twists and turns. But the same holds for many of the words in an English dictionary.
The word cabbageheaded is the longest word that consists entirely of letters from the first half of the alphabet (a–m). The word nontortuous is the longest word that consists entirely of letters from the second half of alphabet (n–z).
We can also search for words that alternate between letters from the first half and the second half of the alphabet. The longest alternating words starting with a letter from the first half of the alphabet have 12 letters. Examples include comparatives and itinerariums. The longest alternating words starting with a letter from the second half of the alphabet have 13 letters. Examples include paranephritis and phraseography.
A word only consists of uppercase and lowercase letters. Your task:
Write a function first_position that takes a word (str). The function must return the position in the alphabet (int; A=1, B=2, C=3, …, Z=26) of the alphabetic first letter in the word.
Write a function last_position that takes a word (str). The function must return the position in the alphabet (int; A=1, B=2, C=3, …, Z=26) of the alphabetic last letter in the word.
Write a function isfirst that takes a word (str). The function must return a Boolean value (bool) that indicates whether the word consists entirely of letters from the first half of the alphabet (a–m).
Write a function issecond that takes a word (str). The function must return a Boolean value (bool) that indicates whether the word consists entirely of letters from the second half of the alphabet (n–z).
Write a function isalternate that takes a word (str). The function must return a Boolean value (bool) that indicates whether the word alternates between letters from the first half of the alphabet (a–m) and the second half of the alphabet (n–z).
None of these functions may make a distinction between uppercase and lowercase letters.
>>> position('G')
7
>>> position('v')
22
>>> first_position('FIDDLEDEEDEE')
4
>>> first_position('soupspoons')
14
>>> first_position('CoMpArAtIvEs')
1
>>> first_position('pArAnEpHrItIs')
1
>>> last_position('FIDDLEDEEDEE')
12
>>> last_position('soupspoons')
21
>>> last_position('CoMpArAtIvEs')
22
>>> last_position('pArAnEpHrItIs')
20
>>> isfirst('FIDDLEDEEDEE')
True
>>> isfirst('soupspoons')
False
>>> isfirst('CoMpArAtIvEs')
False
>>> isfirst('pArAnEpHrItIs')
False
>>> issecond('FIDDLEDEEDEE')
False
>>> issecond('soupspoons')
True
>>> issecond('CoMpArAtIvEs')
False
>>> issecond('pArAnEpHrItIs')
False
>>> isalternate('FIDDLEDEEDEE')
False
>>> isalternate('soupspoons')
False
>>> isalternate('CoMpArAtIvEs')
True
>>> isalternate('pArAnEpHrItIs')
True