I am trying to take an input as 'democracy is overrated.'and returns 'democr _acy is underrat_ed'
sentence= input()
suffixes = ["acy","tion", "ate",
"er", "fy", "ize", "able", "ible", "al",
"esque", "ful", "ic", "ous", "ish", "ive",
"less", "ed"]
for pattern in suffixes :
if pattern in sentence:
out = ''
par = sentence.partition(pattern)
while par[1]:
out += ' _'.join([par[0], par[1]])
remainder = par[2]
par = par[2].partition(pattern)
sentence = ''.join([out, remainder])
print(''.join([out, remainder]))
as you can see my output is 'democr _acy is ov _err _at _ed.' I know that I have to search for a suffix at the end of the sentence and split into meaningful suffixes.To do that I thought sentence.endswith may work,but actually I am not sure how I can do this:(