If a string contains a suffix from a list, how do I strip that specific suffix from the string?
<p>I have a list of strings and a list of suffixes. If a string contains one of the suffixes, how do I strip that specific one from the string? </p>

<pre><code>b = ["food", "stuffing", "hobbitses"]
y = ["ing", "es", "s", "ly"]


def stemming():
    for i in range(len(b)):
        if b[i].endswith(tuple(y)):
            b[i] = b[i] - #???
print b
</code></pre>

<p>I'd recommend separating out the stem removal into its own function, and then using a list comprehension or a separate function for the whole list.  Here's one way of doing it</p>

<pre><code>def remove_stems(word, stems):
    for stem in stems:
        if word.endswith(stem):
            return word[:-len(stem)]
        else: 
            return word

b_without_stems = [remove_stem(word, stems) for word in b]
</code></pre>

python string python-2.7 stemming