Last active
August 16, 2017 15:08
-
-
Save nozma/ac256c1476b2757a279e6aabccb01ea0 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 numpy.random as rd | |
| def gen_typo(S): | |
| if len(S) <= 4: | |
| return S | |
| else: | |
| idx = [0] | |
| idx.extend(rd.choice(range(1, len(S)-1), len(S)-2, replace=False)) | |
| idx.append(len(S)-1) | |
| result = [] | |
| for i in range(len(S)): | |
| result.append(S[idx[i]]) | |
| return ''.join(result) | |
| s = "I couldn't believe that I could actually understand what I was reading : the phenomenal power of the human mind ." | |
| s = s.split() | |
| print(' '.join([gen_typo(i) for i in s])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment