I am using Alko's code from Expanding English language contractions in Python
I added a bit code. I do not understand why I am getting this =>KeyError: "Didn't"
import re
import csv
fileLocation = 'test.csv'
cList = {
"ain't": "am not",
"aren't": "are not",
"can't": "cannot",
"can't've": "cannot have",
"'cause": "because",
"could've": "could have",
"couldn't": "could not",
"couldn't've": "could not have",
"didn't": "did not",
"doesn't": "does not",
}
R = re.compile('(%s)' % '|'.join(cList.keys()),re.IGNORECASE)
read = csv.reader(open(fileLocation))
aList = []
def expandContractions(text,R=R):
def replace(match):
return cList[match.group(0)]
return R.sub(replace, text)
for i in read:
aList.append(i[5])
for j in aList:
print(expandContractions(j))