Skip to content

Instantly share code, notes, and snippets.

@ironhouzi
Created May 28, 2015 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ironhouzi/519dda3f57a322e45f36 to your computer and use it in GitHub Desktop.
Save ironhouzi/519dda3f57a322e45f36 to your computer and use it in GitHub Desktop.
Python optimization problem
def validWylie(self, syllable):
return syllable.wylie.startswith(self.ga_prefix) \
or not any(char not in self.latin_set for char in syllable.wylie)
# called with: if not validWylie(somesyllable): ...
# runs at 10.7 seconds on test case
def invalidWylie(self, syllable):
if not syllable.wylie.startswith(self.ga_prefix):
for c in syllable.wylie:
if c not in self.latin_set:
return True
return False
# called with: if invalidWylie(somesyllable): ...
# runs at 10.3 seconds on test case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment