1

I want to slice the affixes from stem. I tried the suffixes with the following command and it was OK for 'dishes'. However when I want to do it with a prefix (for example, 'undo'), how can I define the prefix in Python to get the result of un-do?

>>> def stem(word):
    for suffix in ['ing', 'lity', 'es']:
        if word.endswith(suffix):
            return word[:-len(suffix)]
        return word
>>> re.findall(r'^(.*)(ing|lity|es)$', 'dishes')
[('dish', 'es')]
mu is too short
  • 426,620
  • 70
  • 833
  • 800
Oliver
  • 13
  • 2

1 Answers1

2

Well, why not use regulare expressions the same way you did ?

>>> re.findall(r'^(un|ir)(.*)$', 'undo')
[('un', 'do')]
Emmanuel
  • 13,935
  • 12
  • 50
  • 72