Last active
June 6, 2023 13:20
-
-
Save willwest/ca5d050fdf15232a9e67 to your computer and use it in GitHub Desktop.
Longest Common Suffix - Python
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
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