Last active
August 28, 2017 13:56
-
-
Save nozma/45e5f33b323456487fbcd870283eff79 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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