Skip to content

Instantly share code, notes, and snippets.

@tzengyuxio
Created November 30, 2011 16:43
Show Gist options
  • Save tzengyuxio/1409748 to your computer and use it in GitHub Desktop.
Save tzengyuxio/1409748 to your computer and use it in GitHub Desktop.
Generate misspelling words...
#!/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'"
print
return
input_str = sys.argv[1]
output_str = ' '.join([ misspell(x) for x in input_str.split() ])
print
print "[input]: " + input_str
print "[output]: " + output_str
print
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment