Skip to content

Instantly share code, notes, and snippets.

@willwest
Last active June 6, 2023 13:20
Show Gist options
  • Save willwest/ca5d050fdf15232a9e67 to your computer and use it in GitHub Desktop.
Save willwest/ca5d050fdf15232a9e67 to your computer and use it in GitHub Desktop.
Longest Common Suffix - Python
import os
# Return the longest common suffix in a list of strings
def longest_common_suffix(list_of_strings):
reversed_strings = [' '.join(s.split()[::-1]) for s in list_of_strings]
reversed_lcs = os.path.commonprefix(reversed_strings)
lcs = ' '.join(reversed_lcs.split()[::-1])
return lcs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment