Created
November 20, 2012 09:59
-
-
Save brouberol/4117062 to your computer and use it in GitHub Desktop.
Remove common suffix of several strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os.path import commonprefix | |
def common_suffix(titles): | |
""" Return the common suffix of all the strings contained in the | |
argument list. | |
:param titles: a list of strings | |
Example: | |
>>> titles = [u'Homepage | wondercity', u'Page 1 | wondercity'] | |
>>> common_suffix(titles) | |
u' | wondercity' | |
""" | |
return commonprefix([title[::-1] for title in titles])[::-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment