A digraph is a pair of characters used in the orthography of a language to write a single phoneme (a distinct sound). In English, the correct spelling of a word may greatly differ from its pronunciation. If one is unsure whether a word is spelled with the digraph ei or ei, the mnemonic rule of thumb
I before E, except after C
suggests that the correct order is ie, unless the digraph is preceded by the letter c. In that case, it must be spelled as ei. Because of its simplicity, the rhyme is widely known in the Anglo-Saxon world. Edward Carney even calls it
this supreme, and for many people solitary, spelling rule
However, there are many common exceptions to "I before E …":
albeit, beige, counterfeit, deity, either, feisty, height, kaleidoscope, leisure, neighbor, obeisance, protein, reveille, seize, veil, weird, zeitgeist
"… except after C":
ancient, concierge, efficient, financier, glacier, juicier, democracies, species
such that Will Rogers once said:
Nothing you can't spell will ever work.
An English word is a sequence of one or more letters, hyphens (-) and quotation marks ('). You may assume that there's always at least one character between two occurrences of the digraphs ei and ie in an English word. English words such as boogieing, sortieing or Weierstrass will therefore never occur in this assignment.
The English words in an English sentence are the longest possible sequences of one or more letters, hyphens (-) and quotation marks ('). As such, eighty-eight is a single word, as is O'Reilly.
Your task:
Write a function fill that takes two arguments: i) a lowercase English word $$w$$ (str) in which all occurrences of the digraphs ei and ie have been replaced by two question marks (??) and ii) a Boolean value (bool) that indicates whether the correct spelling of the word is an exception to the rule of thumb "I before E, except after C". The function may assume that either all occurrences of the digraphs ie and ei are exceptions or none of them is an exception. The function must return the correct spelling of word $$w$$.
Write a function mask that takes a lowercase English word $$w$$ (str). The function must return word $$w$$ in which all occurrences of the digraphs ei and ie have been replaced by two question marks (??).
Write a function isexception that takes the correct spelling of an English word $$w$$ (str). The function must return a Boolean value (bool) that indicates whether word $$w$$ is an exception to the rule of thumb "I before E, except after C".
Write a function exceptions that takes the correct spelling of an English sentence (str). The function must return how many (int) English words in the sentence are an exception to the rule of thumb "I before E, except after C".
>>> fill('h??roglyphic', False)
'hieroglyphic'
>>> fill('inconc??vable', False)
'inconceivable'
>>> fill('fr??ndl??st', False)
'friendliest'
>>> fill('programmer', False)
'programmer'
>>> fill('alb??t', True)
'albeit'
>>> fill('z??tg??st', True)
'zeitgeist'
>>> fill('conc??rge', True)
'concierge'
>>> fill('glac??r', True)
'glacier'
>>> mask('hieroglyphic')
'h??roglyphic'
>>> mask('inconceivable')
'inconc??vable'
>>> mask('friendliest')
'fr??ndl??st'
>>> mask('programmer')
'programmer'
>>> mask('albeit')
'alb??t'
>>> mask('zeitgeist')
'z??tg??st'
>>> mask('concierge')
'conc??rge'
>>> mask('glacier')
'glac??r'
>>> isexception('hierarchy')
False
>>> isexception('ancient')
True
>>> isexception('ceiling')
False
>>> isexception('fahrenheit')
True
>>> isexception('daily')
False
>>> exceptions('I believe in the power of education.')
0
>>> exceptions('The ancient recipe requires a dash of weird ingredients.')
2
>>> exceptions('The society was fraught with a weird sense of hierarchy.')
2
>>> exceptions('The efficient machine processed the data with great speed.')
1
>>> exceptions('I before E except when your feisty foreign neighbor Keith leisurely receives eight counterfeit beige sleighs from weirdly caffeinated atheist weightlifters')
13
English is easy!
— AlphaFo𝕏 (@Alphafox78) August 24, 20243
Also: 😭 pic.twitter.com/N98jnCl1g22