Change e letters to i in words: Difference between revisions

→‎{{header|Python}}: Draft in response to a replacement notice. (Needs 3.8 for assignment operator)
(→‎{{header|Python}}: Mark incorrect)
(→‎{{header|Python}}: Draft in response to a replacement notice. (Needs 3.8 for assignment operator))
Line 1,115:
 
=={{header|Python}}==
Needs Python 3.8 or above for the assignment operator in the list comprehension.
{{incorrect|Python|Does not actually read words from a file and search e->i words, reads from a given list and blindly replaces e with i.}}
{{Works with|Python|3.8}}
<lang python>unixdict = ['analyses','atlantes','bellow','breton','clench','convect','crises','diagnoses','enfant','enquiry','frances','galatea','harden','heckman','inequity','inflect','jacobean','marten','module','pegging','psychoses','rabbet','sterling','synopses','vector','welles']
<lang python>'''Words twinned by (e -> i) replacement'''
 
strOfUD = str(unixdict)
replacestr = strOfUD.replace("e","i")
print(replacestr)</lang>
 
# ieTwins :: String -> [(String, String)]
{{Out}}
def ieTwins(s):
<pre>['analysis', 'atlantis', 'billow', 'briton', 'clinch', 'convict', 'crisis', 'diagnosis', 'infant', 'inquiry', 'francis', 'galatia', 'hardin', 'hickman', 'iniquity', 'inflict', 'jacobian', 'martin', 'moduli', 'pigging', 'psychosis', 'rabbit', 'stirling', 'synopsis', 'victor', 'willis']</pre>
'''Words in the lines of s which are twinned
with other words in s by replacement of
'e' by 'i'.
'''
allWords = s.splitlines()
lexicon = set(allWords)
 
return [
=== Python Using Lists ===
(w, twin) for w in [
<lang python>unixdict = ['analyses','atlantes','bellow','breton','clench','convect','crises','diagnoses','enfant','enquiry','frances','galatea','harden','heckman','inequity','inflect','jacobean','marten','module','pegging','psychoses','rabbet','sterling','synopses','vector','welles']
w for w in allWords
if 5 < len(w) and 'e' in w
]
if (twin := w.replace('e', 'i')) in lexicon
]
 
newdict = []
 
# ------------------------- TEST -------------------------
for xx in range(0,len(unixdict)):
# main :: IO ()
strOfUD = unixdict[xx]
def main():
replacestr = strOfUD.replace("e","i")
'''Words twinned by ('e' -> 'i') replacement
newdict.append(strOfUD + " ==> " + replacestr)
in unixdict.txt
finaloutput = '\n'.join(newdict)
'''
print(finaloutput)</lang>
for pair in (
ieTwins(
readFile("unixdict.txt")
)
):
print(pair)
 
 
{{Out}}
# ----------------------- GENERIC ------------------------
<pre>analyses ==> analysis
 
atlantes ==> atlantis
# readFile :: FilePath -> IO String
bellow ==> billow
def readFile(fp):
breton ==> briton
'''The contents of any file at the path
clench ==> clinch
derived by expanding any ~ in fp.
convect ==> convict
'''
crises ==> crisis
with open(fp, 'r', encoding='utf-8') as f:
diagnoses ==> diagnosis
return f.read()
enfant ==> infant
 
enquiry ==> inquiry
 
frances ==> francis
# MAIN ---
galatea ==> galatia
if __name__ == '__main__':
harden ==> hardin
main()</lang>
heckman ==> hickman
<pre>('analyses', 'analysis')
inequity ==> iniquity
('atlantes', 'atlantis')
inflect ==> inflict
('bellow', 'billow')
jacobean ==> jacobian
('breton', 'briton')
marten ==> martin
('clench', 'clinch')
module ==> moduli
('convect', 'convict')
pegging ==> pigging
('crises', 'crisis')
psychoses ==> psychosis
('diagnoses', 'diagnosis')
rabbet ==> rabbit
('enfant', 'infant')
sterling ==> stirling
('enquiry', 'inquiry')
synopses ==> synopsis
('frances', 'francis')
vector ==> victor
('galatea', 'galatia')
welles ==> willis</pre>
('harden', 'hardin')
('heckman', 'hickman')
('inequity', 'iniquity')
('inflect', 'inflict')
('jacobean', 'jacobian')
('marten', 'martin')
('module', 'moduli')
('pegging', 'pigging')
('psychoses', 'psychosis')
('rabbet', 'rabbit')
('sterling', 'stirling')
('synopses', 'synopsis')
('vector', 'victor')
('welles', 'willis')</pre>
 
=={{header|Quackery}}==
9,655

edits