Created
October 16, 2018 04:30
-
-
Save edgarrmondragon/449386986e0784e3be38829a062779a0 to your computer and use it in GitHub Desktop.
Custom lexicographical order in 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
alphabet = <CustomAlphabet> | |
def goes_before(s, t): | |
if s == t: | |
return True | |
elif len(t) == 0: | |
return False | |
elif len(s) == 0: | |
return True | |
elif alphabet.index(s[0]) < alphabet.index(t[0]): | |
return True | |
elif alphabet.index(s[0]) > alphabet.index(t[0]): | |
return False | |
else: | |
return goes_before(s[1:], t[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment