Created
September 9, 2015 04:53
-
-
Save oyakata/7105807ddaaf489b9089 to your computer and use it in GitHub Desktop.
文字列のN割をランダムにマスキング
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 main(text, n): | |
| length = len(text) | |
| count = int(length * n / 10) | |
| sample = random.sample(range(length), count) | |
| L = list(text) | |
| for i in sample: | |
| L[i] = '*' | |
| return ''.join(L) | |
| if __name__ == '__main__': | |
| print main('bird in the hand is worth two in the bush', 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment