This is a bit difficult to describe, but I'll do my best.
In Python, I can use
string.startswith(tuple) to test for multiple matches. But
startswith only returns a boolean answer, whether or not it found a match. It is equivalent to
any(string.startswith(substring) for substring in inputTuple). I am looking for a way to return the rest of the string. So, for example:
>>> fruits = ['apple', 'orange', 'pear'] >>> words1 = 'orange, quagga, etc.' >>> words2 = 'giraffe, apple, etc.' >>> magicFunc(words1, fruits) ', quagga, etc.' >>> magicFunc(words2, fruits) False
(I'm also okay with the function returning the first matching string, or a list of matching strings, or anything that would enable me to determine where to cut off the string.)
Right now I have this:
remainingString(bigString, searchStrings): for sub in searchStrings: if bigString.startswith(sub): return bigString.partition(sub)
Ick. Is there anything better?