I know how to solve my problem without using lambda/map (and I can't use regex or other python libraries for this exercise), using a for-loop with string.replace()....but I am really trying to see if I can achieve the same result using a combination of map/lambda and string.replace\
My goal here is to read in a txt file, and then substitute every instance of a non-standard 'e' (like éêèÉÊÈ) with the letter 'e'
My main issue now is that i get 6 lists, (e.g. I have 6 strings in newFile / newFileListComprehension and each string has updated the original string, based on the 1 iterable that was evaluated
e.g. newFile[0] = output of .replace('é'), newFile[1] = output of .replace('ê') etc.
So what I would like, is to return 1 copy of the formatted string, with all of the .replace() iterated over it.
Link to the text file I am referencing below can be accessed https://easyupload.io/s7m0zj
import string
def file2str(filename):
with open(filename, 'r', encoding="utf8") as fid:
return fid.read()
def count_letter_e(filename, ignore_accents, ignore_case):
eSToAvoid = 'éêèÉÊÈ'
textFile = file2str("Sentence One.txt")
newFileListComprehension = [textFile.replace(e,'e') for e in eSToAvoid if ignore_accents == 1]
value = textFile.count('e')
#newFile = list((map(lambda element: (textFile.replace(element, 'e') if ignore_accents == 1 else textFile.count('e')), eSToAvoid)))
return 0
numberOfEs = count_letter_e("Sentence One.txt", 1, 1)```