Skip to content

Instantly share code, notes, and snippets.

@nozma
Last active August 28, 2017 13:56
Show Gist options
  • Save nozma/45e5f33b323456487fbcd870283eff79 to your computer and use it in GitHub Desktop.
Save nozma/45e5f33b323456487fbcd870283eff79 to your computer and use it in GitHub Desktop.
# coding: utf-8
import random
def gen_typo(S):
return ' '.join(
s
# 長さ4以下の単語はそのまま返す
if len(s) <= 4
# 長さ5以上の単語は1文字目と2文字目を残してシャッフル
else s[0] + ''.join(random.sample(s[1:-1], k=len(s)-2)) + s[-1]
for s in S.split()
)
S = "I couldn't believe that I could actually understand what I was reading : the phenomenal power of the human mind ."
print(gen_typo(S))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment