Skip to content

Instantly share code, notes, and snippets.

@brouberol
Created November 20, 2012 09:59
Show Gist options
  • Save brouberol/4117062 to your computer and use it in GitHub Desktop.
Save brouberol/4117062 to your computer and use it in GitHub Desktop.
Remove common suffix of several strings
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