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)
Thundergnat (talk | contribs) (→{{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.
{{Works with|Python|3.8}}
<lang python>'''Words twinned by (e -> i) replacement'''
# ieTwins :: String -> [(String, String)]
def ieTwins(s):
'''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 [
(w, twin) for w in [
w for w in allWords
if 5 < len(w) and 'e' in w
]
if (twin := w.replace('e', 'i')) in lexicon
]
# ------------------------- TEST -------------------------
# main :: IO ()
def main():
'''Words twinned by ('e' -> 'i') replacement
in unixdict.txt
'''
for pair in (
ieTwins(
readFile("unixdict.txt")
)
):
print(pair)
# ----------------------- GENERIC ------------------------
# readFile :: FilePath -> IO String
def readFile(fp):
'''The contents of any file at the path
derived by expanding any ~ in fp.
'''
with open(fp, 'r', encoding='utf-8') as f:
return f.read()
# MAIN ---
if __name__ == '__main__':
main()</lang>
<pre>('analyses', 'analysis')
('atlantes', 'atlantis')
('bellow', 'billow')
('breton', 'briton')
('clench', 'clinch')
('convect', 'convict')
('crises', 'crisis')
('diagnoses', 'diagnosis')
('enfant', 'infant')
('enquiry', 'inquiry')
('frances', 'francis')
('galatea', 'galatia')
('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}}==
|