Created
November 30, 2011 16:43
-
-
Save tzengyuxio/1409748 to your computer and use it in GitHub Desktop.
Generate misspelling words...
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
#!/usr/bin/python | |
import sys | |
import random | |
def misspell(s): | |
# word and punctation | |
(w, p) = (s, '') if s[-1] not in [',', '.', ';', ':'] else (s[:-1], s[-1]) | |
if len(w) <= 3: | |
return s | |
mid = [x for x in w[1:-1]] | |
random.shuffle(mid) | |
return w[0] + ''.join(mid) + w[-1] + p | |
def main(): | |
if len(sys.argv) < 2: | |
print "Usage: type 'the sentence you want to misspelling'" | |
return | |
input_str = sys.argv[1] | |
output_str = ' '.join([ misspell(x) for x in input_str.split() ]) | |
print "[input]: " + input_str | |
print "[output]: " + output_str | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment