Skip to content

Instantly share code, notes, and snippets.

@edgarrmondragon
Created October 16, 2018 04:30
Show Gist options
  • Save edgarrmondragon/449386986e0784e3be38829a062779a0 to your computer and use it in GitHub Desktop.
Save edgarrmondragon/449386986e0784e3be38829a062779a0 to your computer and use it in GitHub Desktop.
Custom lexicographical order in Python
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