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>assuming you want to strip the first suffix found this will do it</p>

<pre><code>def stemming(strings, endings):
    for i, string in enumerate(strings):
        for ending in endings:
            if string.endswith(ending):
                strings[i] = string[:-len(ending)]
                continue
</code></pre>

python string python-2.7 stemming